"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "packages/hoppscotch-js-sandbox/src/__tests__/testing/expect/toHaveLength.spec.ts" between
hoppscotch-2.2.1.tar.gz and hoppscotch-3.0.0.tar.gz

About: Hoppscotch is a light-weight, web based API development suite.

toHaveLength.spec.ts  (hoppscotch-2.2.1):toHaveLength.spec.ts  (hoppscotch-3.0.0)
import * as TE from "fp-ts/TaskEither"
import { pipe } from "fp-ts/function"
import { execTestScript, TestResponse } from "../../../test-runner" import { execTestScript, TestResponse } from "../../../test-runner"
const fakeResponse: TestResponse = { const fakeResponse: TestResponse = {
status: 200, status: 200,
body: "hoi", body: "hoi",
headers: [], headers: [],
} }
const func = (script: string, res: TestResponse) =>
pipe(
execTestScript(script, { global: [], selected: [] }, res),
TE.map((x) => x.tests)
)
describe("toHaveLength", () => { describe("toHaveLength", () => {
test("asserts true for valid lengths with no negation", () => { test("asserts true for valid lengths with no negation", () => {
return expect( return expect(
execTestScript( func(
` `
pw.expect([1, 2, 3, 4]).toHaveLength(4) pw.expect([1, 2, 3, 4]).toHaveLength(4)
pw.expect([]).toHaveLength(0) pw.expect([]).toHaveLength(0)
`, `,
fakeResponse fakeResponse
)() )()
).resolves.toEqualRight([ ).resolves.toEqualRight([
expect.objectContaining({ expect.objectContaining({
expectResults: [ expectResults: [
{ status: "pass", message: "Expected the array to be of length '4'" }, { status: "pass", message: "Expected the array to be of length '4'" },
{ status: "pass", message: "Expected the array to be of length '0'" }, { status: "pass", message: "Expected the array to be of length '0'" },
], ],
}), }),
]) ])
}) })
test("asserts false for invalid lengths with no negation", () => { test("asserts false for invalid lengths with no negation", () => {
return expect( return expect(
execTestScript( func(
` `
pw.expect([]).toHaveLength(4) pw.expect([]).toHaveLength(4)
pw.expect([1, 2, 3, 4]).toHaveLength(0) pw.expect([1, 2, 3, 4]).toHaveLength(0)
`, `,
fakeResponse fakeResponse
)() )()
).resolves.toEqualRight([ ).resolves.toEqualRight([
expect.objectContaining({ expect.objectContaining({
expectResults: [ expectResults: [
{ status: "fail", message: "Expected the array to be of length '4'" }, { status: "fail", message: "Expected the array to be of length '4'" },
{ status: "fail", message: "Expected the array to be of length '0'" }, { status: "fail", message: "Expected the array to be of length '0'" },
], ],
}), }),
]) ])
}) })
test("asserts false for valid lengths with negation", () => { test("asserts false for valid lengths with negation", () => {
return expect( return expect(
execTestScript( func(
` `
pw.expect([1, 2, 3, 4]).not.toHaveLength(4) pw.expect([1, 2, 3, 4]).not.toHaveLength(4)
pw.expect([]).not.toHaveLength(0) pw.expect([]).not.toHaveLength(0)
`, `,
fakeResponse fakeResponse
)() )()
).resolves.toEqualRight([ ).resolves.toEqualRight([
expect.objectContaining({ expect.objectContaining({
expectResults: [ expectResults: [
{ {
skipping to change at line 75 skipping to change at line 83
status: "fail", status: "fail",
message: "Expected the array to not be of length '0'", message: "Expected the array to not be of length '0'",
}, },
], ],
}), }),
]) ])
}) })
test("asserts true for invalid lengths with negation", () => { test("asserts true for invalid lengths with negation", () => {
return expect( return expect(
execTestScript( func(
` `
pw.expect([]).not.toHaveLength(4) pw.expect([]).not.toHaveLength(4)
pw.expect([1, 2, 3, 4]).not.toHaveLength(0) pw.expect([1, 2, 3, 4]).not.toHaveLength(0)
`, `,
fakeResponse fakeResponse
)() )()
).resolves.toEqualRight([ ).resolves.toEqualRight([
expect.objectContaining({ expect.objectContaining({
expectResults: [ expectResults: [
{ {
skipping to change at line 100 skipping to change at line 108
status: "pass", status: "pass",
message: "Expected the array to not be of length '0'", message: "Expected the array to not be of length '0'",
}, },
], ],
}), }),
]) ])
}) })
test("gives error if not called on an array or a string with no negation", () => { test("gives error if not called on an array or a string with no negation", () => {
return expect( return expect(
execTestScript( func(
` `
pw.expect(5).toHaveLength(0) pw.expect(5).toHaveLength(0)
pw.expect(true).toHaveLength(0) pw.expect(true).toHaveLength(0)
`, `,
fakeResponse fakeResponse
)() )()
).resolves.toEqualRight([ ).resolves.toEqualRight([
expect.objectContaining({ expect.objectContaining({
expectResults: [ expectResults: [
{ {
skipping to change at line 127 skipping to change at line 135
message: message:
"Expected toHaveLength to be called for an array or string", "Expected toHaveLength to be called for an array or string",
}, },
], ],
}), }),
]) ])
}) })
test("gives error if not called on an array or a string with negation", () => { test("gives error if not called on an array or a string with negation", () => {
return expect( return expect(
execTestScript( func(
` `
pw.expect(5).not.toHaveLength(0) pw.expect(5).not.toHaveLength(0)
pw.expect(true).not.toHaveLength(0) pw.expect(true).not.toHaveLength(0)
`, `,
fakeResponse fakeResponse
)() )()
).resolves.toEqualRight([ ).resolves.toEqualRight([
expect.objectContaining({ expect.objectContaining({
expectResults: [ expectResults: [
{ {
skipping to change at line 154 skipping to change at line 162
message: message:
"Expected toHaveLength to be called for an array or string", "Expected toHaveLength to be called for an array or string",
}, },
], ],
}), }),
]) ])
}) })
test("gives an error if toHaveLength parameter is not a number without negatio n", () => { test("gives an error if toHaveLength parameter is not a number without negatio n", () => {
return expect( return expect(
execTestScript( func(
` `
pw.expect([1, 2, 3, 4]).toHaveLength("a") pw.expect([1, 2, 3, 4]).toHaveLength("a")
`, `,
fakeResponse fakeResponse
)() )()
).resolves.toEqualRight([ ).resolves.toEqualRight([
expect.objectContaining({ expect.objectContaining({
expectResults: [ expectResults: [
{ {
status: "error", status: "error",
message: "Argument for toHaveLength should be a number", message: "Argument for toHaveLength should be a number",
}, },
], ],
}), }),
]) ])
}) })
test("gives an error if toHaveLength parameter is not a number with negation", () => { test("gives an error if toHaveLength parameter is not a number with negation", () => {
return expect( return expect(
execTestScript( func(
` `
pw.expect([1, 2, 3, 4]).not.toHaveLength("a") pw.expect([1, 2, 3, 4]).not.toHaveLength("a")
`, `,
fakeResponse fakeResponse
)() )()
).resolves.toEqualRight([ ).resolves.toEqualRight([
expect.objectContaining({ expect.objectContaining({
expectResults: [ expectResults: [
{ {
status: "error", status: "error",
 End of changes. 10 change blocks. 
8 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)