Merge pull request #1398 from carlos-ds/unit-tests
Unit tests for the remaining test methods
This commit is contained in:
@@ -19,6 +19,11 @@ describe("Error handling", () => {
|
||||
test("errors array is empty on a successful test", () => {
|
||||
expect(getErrors("pw.expect(1).toBe(1)")).toStrictEqual([])
|
||||
})
|
||||
test("throws error at a variable which is not declared", () => {
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("someVariable")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBe", () => {
|
||||
@@ -62,3 +67,133 @@ describe("toHaveProperty", () => {
|
||||
).toEqual(FAIL)
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeLevel2xx", () => {
|
||||
test("test for numbers", () => {
|
||||
expect(getTestResult("pw.expect(200).toBeLevel2xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(200).not.toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(300).toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(300).not.toBeLevel2xx()", 0)).toEqual(PASS)
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('200').toBeLevel2xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('200').not.toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('300').toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('300').not.toBeLevel2xx()", 0)).toEqual(PASS)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel2xx()", 0)).toEqual(FAIL)
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel2xx()")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeLevel3xx()", () => {
|
||||
test("test for numbers", () => {
|
||||
expect(getTestResult("pw.expect(300).toBeLevel3xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(300).not.toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(400).toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(400).not.toBeLevel3xx()", 0)).toEqual(PASS)
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('300').toBeLevel3xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('300').not.toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('400').toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('400').not.toBeLevel3xx()", 0)).toEqual(PASS)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel3xx()", 0)).toEqual(FAIL)
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel3xx()")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeLevel4xx()", () => {
|
||||
test("test for numbers", () => {
|
||||
expect(getTestResult("pw.expect(400).toBeLevel4xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(400).not.toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(500).toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(500).not.toBeLevel4xx()", 0)).toEqual(PASS)
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('400').toBeLevel4xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('400').not.toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('500').toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('500').not.toBeLevel4xx()", 0)).toEqual(PASS)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel4xx()", 0)).toEqual(FAIL)
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel4xx()")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeLevel5xx()", () => {
|
||||
test("test for numbers", () => {
|
||||
expect(getTestResult("pw.expect(500).toBeLevel5xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(500).not.toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(200).toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(200).not.toBeLevel5xx()", 0)).toEqual(PASS)
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('500').toBeLevel5xx()", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('500').not.toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('200').toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('200').not.toBeLevel5xx()", 0)).toEqual(PASS)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel5xx()", 0)).toEqual(FAIL)
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel5xx()")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toHaveLength()", () => {
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('word').toHaveLength(4)", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect('word').toHaveLength(5)", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('word').not.toHaveLength(4)", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect('word').not.toHaveLength(5)", 0)).toEqual(PASS)
|
||||
})
|
||||
test("test for arrays", () => {
|
||||
const fruits = "['apples', 'bananas', 'oranges', 'grapes', 'strawberries', 'cherries']"
|
||||
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(6)`, 0)).toEqual(PASS)
|
||||
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(7)`, 0)).toEqual(FAIL)
|
||||
expect(getTestResult(`pw.expect(${fruits}).not.toHaveLength(6)`, 0)).toEqual(FAIL)
|
||||
expect(getTestResult(`pw.expect(${fruits}).not.toHaveLength(7)`, 0)).toEqual(PASS)
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeType()", () => {
|
||||
test("test for positive assertion", () => {
|
||||
expect(getTestResult("pw.expect('random').toBeType('string')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(true).toBeType('boolean')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(5).toBeType('number')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(new Date()).toBeType('object')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(undefined).toBeType('undefined')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(BigInt(123)).toBeType('bigint')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(Symbol('test')).toBeType('symbol')", 0)).toEqual(PASS)
|
||||
expect(getTestResult("pw.expect(function() {}).toBeType('function')", 0)).toEqual(PASS)
|
||||
})
|
||||
test("test for negative assertion", () => {
|
||||
expect(getTestResult("pw.expect('random').not.toBeType('string')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(true).not.toBeType('boolean')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(5).not.toBeType('number')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(new Date()).not.toBeType('object')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(undefined).not.toBeType('undefined')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(BigInt(123)).not.toBeType('bigint')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(Symbol('test')).not.toBeType('symbol')", 0)).toEqual(FAIL)
|
||||
expect(getTestResult("pw.expect(function() {}).not.toBeType('function')", 0)).toEqual(FAIL)
|
||||
})
|
||||
test("unexpected type", () => {
|
||||
expect(getTestResult("pw.expect('random').toBeType('unknown')", 0)).toEqual(FAIL)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -109,7 +109,7 @@ class Expectation {
|
||||
)
|
||||
}
|
||||
toBeLevel2xx() {
|
||||
const code = parseInt(this.expectValue)
|
||||
const code = parseInt(this.expectValue, 10)
|
||||
if (Number.isNaN(code)) {
|
||||
return this._fail(`Expected 200-level status but could not parse value ${this.expectValue}`)
|
||||
}
|
||||
@@ -118,7 +118,7 @@ class Expectation {
|
||||
: this._fail(this._fmtNot(`Expected ${this.expectValue} to (not)be 200-level status`))
|
||||
}
|
||||
toBeLevel3xx() {
|
||||
const code = parseInt(this.expectValue)
|
||||
const code = parseInt(this.expectValue, 10)
|
||||
if (Number.isNaN(code)) {
|
||||
return this._fail(`Expected 300-level status but could not parse value ${this.expectValue}`)
|
||||
}
|
||||
@@ -127,7 +127,7 @@ class Expectation {
|
||||
: this._fail(this._fmtNot(`Expected ${this.expectValue} to (not)be 300-level status`))
|
||||
}
|
||||
toBeLevel4xx() {
|
||||
const code = parseInt(this.expectValue)
|
||||
const code = parseInt(this.expectValue, 10)
|
||||
if (Number.isNaN(code)) {
|
||||
return this._fail(`Expected 400-level status but could not parse value ${this.expectValue}`)
|
||||
}
|
||||
@@ -136,7 +136,7 @@ class Expectation {
|
||||
: this._fail(this._fmtNot(`Expected ${this.expectValue} to (not)be 400-level status`))
|
||||
}
|
||||
toBeLevel5xx() {
|
||||
const code = parseInt(this.expectValue)
|
||||
const code = parseInt(this.expectValue, 10)
|
||||
if (Number.isNaN(code)) {
|
||||
return this._fail(`Expected 500-level status but could not parse value ${this.expectValue}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user