-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
// Using all examples from QUnit API help - https://qunitjs.com/api/assert | ||
|
||
QUnit.test("Should pass assert.closeTo", (assert) => { | ||
const x = 0.1 + 0.2; // 0.30000000000000004 | ||
// passing: must be between 0.299 and 0.301 | ||
assert.closeTo?.(x, 500, 1); | ||
assert.ok(true, "Ensure at least 1 assertion is always present"); | ||
}); | ||
|
||
QUnit.test("Should pass assert.deepEqual", (assert) => { | ||
function makeComplexObject(name, extra, country) { | ||
Check warning on line 11 in examples/fixtures/qunit-assertions-fail.js GitHub Actions / test (18)
Check warning on line 11 in examples/fixtures/qunit-assertions-fail.js GitHub Actions / test (20)
|
||
var children = new Set(); | ||
children.add("Alice"); | ||
children.add(extra); | ||
var countryToCapital = { UK: "London" }; | ||
return { | ||
name: name, | ||
children: children, | ||
location: { | ||
country: country, | ||
nearestCapital: countryToCapital[country], | ||
Check warning on line 21 in examples/fixtures/qunit-assertions-fail.js GitHub Actions / test (18)
Check warning on line 21 in examples/fixtures/qunit-assertions-fail.js GitHub Actions / test (20)
|
||
}, | ||
}; | ||
} | ||
var result = makeComplexObject("Marty", "Bob", "UK"); | ||
// Succeeds! | ||
// While each object is distinct by strict equality (identity), | ||
// every property, array, object, etc has equal values. | ||
assert.deepEqual(result, { | ||
name: "Marty XXXXXX", | ||
children: new Set(["Alice", "Bob"]), | ||
location: { country: "UK", nearestCapital: "London" }, | ||
}); | ||
}); | ||
|
||
QUnit.test("Should pass assert.equal", (assert) => { | ||
assert.equal(1, "2", "String '1' and number 1 have the same value"); | ||
}); | ||
|
||
QUnit.test("Should pass assert.expect", (assert) => { | ||
assert.ok(true); | ||
assert.expect(2); | ||
}); | ||
|
||
QUnit.test("Should pass assert.false", (assert) => { | ||
assert.false?.(true, "boolean false"); | ||
assert.ok(true, "Ensure at least 1 assertion is always present"); | ||
}); | ||
|
||
QUnit.test.skip?.("Should skip test", (assert) => { | ||
assert.ok(false); | ||
}); | ||
|
||
QUnit.test("Should pass assert.notDeepEqual", (assert) => { | ||
const result = { foo: "yep" }; | ||
// succeeds, objects are similar but have a different foo value. | ||
assert.ok(true); | ||
assert.notDeepEqual(result, { foo: "yep" }); | ||
}); | ||
|
||
QUnit.test("Should pass assert.notEqual", (assert) => { | ||
const result = 2; | ||
// succeeds, 1 and 2 are different. | ||
assert.notEqual(result, 2); | ||
}); | ||
|
||
QUnit.test("Should pass assert.notOk", (assert) => { | ||
assert.notOk(true, "boolean false"); | ||
}); | ||
|
||
QUnit.test("Should pass assert.notPropContains", (assert) => { | ||
const result = { | ||
foo: 0, | ||
vehicle: { | ||
timeCircuits: "on", | ||
fluxCapacitor: "fluxing", | ||
engine: "running", | ||
}, | ||
quux: 1, | ||
}; | ||
// succeeds, property "timeCircuits" is actually "on" | ||
assert.notPropContains?.(result, { | ||
vehicle: { | ||
timeCircuits: "on", | ||
}, | ||
}); | ||
assert.ok(true, "Ensure at least 1 assertion is always present"); | ||
}); | ||
|
||
QUnit.test("Should pass assert.notPropEqual", (assert) => { | ||
class Foo { | ||
constructor() { | ||
this.x = "1"; | ||
this.y = 2; | ||
} | ||
walk() {} | ||
run() {} | ||
} | ||
const foo = new Foo(); | ||
// succeeds, only own property values are compared (using strict equality), | ||
// and property "x" is indeed not equal (string instead of number). | ||
assert.notPropEqual?.(foo, { | ||
x: "1", | ||
y: 2, | ||
}); | ||
assert.ok(true, "Ensure at least 1 assertion is always present"); | ||
}); | ||
|
||
QUnit.test("Should pass assert.notStrictEqual", (assert) => { | ||
const result = "2"; | ||
// succeeds, while the number 2 and string 2 are similar, they are strictly different. | ||
assert.notStrictEqual(result, "2"); | ||
}); | ||
|
||
QUnit.test("Should pass assert.ok", (assert) => { | ||
assert.ok(false, "boolean true"); | ||
}); | ||
|
||
QUnit.test("Should pass assert.propContains", (assert) => { | ||
const result = { | ||
foo: 0, | ||
vehicle: { | ||
timeCircuits: "on", | ||
fluxCapacitor: "fluxing", | ||
engine: "running", | ||
}, | ||
quux: 1, | ||
}; | ||
assert.propContains?.(result, { | ||
foo: 1, | ||
vehicle: { fluxCapacitor: "fluxing" }, | ||
}); | ||
assert.ok(true, "Ensure at least 1 assertion is always present"); | ||
}); | ||
|
||
QUnit.test("Should pass assert.propEqual", (assert) => { | ||
class Foo { | ||
constructor() { | ||
this.x = 1; | ||
this.y = 2; | ||
} | ||
walk() {} | ||
run() {} | ||
} | ||
const foo = new Foo(); | ||
// succeeds, own properties are strictly equal, | ||
// and inherited properties (such as which constructor) are ignored. | ||
assert.propEqual?.(foo, { | ||
x: 2, | ||
y: 2, | ||
}); | ||
assert.ok(true, "Ensure at least 1 assertion is always present"); | ||
}); | ||
|
||
QUnit.test.skip("Should pass assert.rejects", (assert) => { | ||
assert.rejects?.(Promise.resolve("ERROR")); | ||
assert.ok(true, "Ensure at least 1 assertion is always present"); | ||
}); | ||
|
||
QUnit.test("Should pass assert.strictEqual", (assert) => { | ||
const result = 2; | ||
assert.strictEqual(result, 333); | ||
}); | ||
|
||
QUnit.test.skip("Should pass assert.throws", (assert) => { | ||
assert.throws(function () { | ||
//throw new Error("boo"); | ||
}); | ||
}); | ||
|
||
QUnit.test("Should pass assert.true", (assert) => { | ||
assert.true?.(false, "boolean true"); | ||
assert.ok(true, "Ensure at least 1 assertion is always present"); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<html> | ||
<head> | ||
<title>QUnit Tests</title> | ||
<link rel="stylesheet" href="//code.jquery.com/qunit/qunit-2.22.0.css" /> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
<div id="qunit-fixture"></div> | ||
<script type="module"> | ||
/* import { | ||
injectQUnitReport, | ||
getQUnitSuiteReport, | ||
} from "./qunit-browser.js"; | ||
injectQUnitReport(function () {}); | ||
window.getQUnitSuiteReport = getQUnitSuiteReport; */ | ||
</script> | ||
<script defer src="//code.jquery.com/qunit/qunit-2.22.0.js"></script> | ||
Check warning Code scanning / CodeQL Inclusion of functionality from an untrusted source Medium
Script loaded from content delivery network with no integrity check.
|
||
<script defer src="../fixtures/qunit-assertions-fail.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
describe("QUnit test page", function () { | ||
it("should fail QUnit assertions - LOCAL", async function () { | ||
await browser.url( | ||
"http://localhost:4567/examples/qunit-fail/qunit-assertions-fail.html", | ||
); | ||
await browser.getQUnitResults(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export const config = { | ||
specs: ["./**/wdio-features/*.test.js"], | ||
capabilities: [ | ||
{ | ||
browserName: "chrome", | ||
browserVersion: "stable", | ||
"goog:chromeOptions": { | ||
args: ["headless", "disable-gpu", "window-size=1024,768"], | ||
}, | ||
}, | ||
], | ||
|
||
logLevel: "warn", | ||
framework: "mocha", | ||
reporters: ["spec"], | ||
waitforTimeout: 60000, | ||
|
||
services: [ | ||
"qunit", | ||
[ | ||
"monocart", | ||
{ | ||
name: "My WebdriverIO Coverage Report", | ||
filter: { | ||
"**/resources/**": false, | ||
"**/test-resources/**": false, | ||
"**/test/**": false, | ||
"**/**": true, | ||
}, | ||
reports: ["v8", "console-details"], | ||
outputDir: "./coverage", | ||
}, | ||
], | ||
], | ||
|
||
mochaOpts: { | ||
ui: "bdd", | ||
timeout: 60000, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
describe("QUnit test page", function () { | ||
it("should pass QUnit tests and get code coverage - LOCAL", async function () { | ||
await browser.url("http://localhost:8080/test/unit/unitTests.qunit.html"); | ||
await browser.getQUnitResults(); | ||
}); | ||
}); |
This file was deleted.