Files
cefsharp/CefSharp.Example/Resources/PostMessageTest.html
Timo Tijhof d06d5100be Example - Simplify BindObjectAsync tests with QUnit (#3298)
* Example - Update to QUnit 2.10

Follows ae41e10d71, which introduced a few references
to QUnit 2.10.

* Example - Simplify the BindObjectAsync unit tests

The `QUnit.test()` may take an async function and/or to return a Promise.
This uses JavaScript's native async/await capabilities to wait for that,
much the same way manual tracking via `assert.async()` would.
Using this can simplify the test structures by a lot.

`assert.rejects()` asserts that a promise throws an error.
`assert.throws()` asserts that a block directly throws an error.

I've also tried to use `assert.deepEqual()`. I suspect a copy
of this function was placed here directly, but I couldn't find
in the history why, so perhaps worth trying if the built-in
one now works.
2020-12-16 10:59:23 +10:00

53 lines
1.5 KiB
HTML

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Post Message Test</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.10.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://code.jquery.com/qunit/qunit-2.10.0.js"></script>
<script type="text/javascript">
let PostMessageIntTestCallback;
(async () =>
{
QUnit.test("PostMessage Object Test:", function (assert)
{
var asyncCallback = assert.async();
const expectedResult = 'Update';
let responseFunc = function (msg)
{
assert.equal(expectedResult, msg, "Return result " + expectedResult);
asyncCallback();
};
CefSharp.PostMessage({ "Type": "Update", Data: { "Property": 123 }, "Callback": responseFunc });
});
QUnit.test("PostMessage Int Test:", function (assert)
{
var asyncCallback = assert.async();
const expectedResult = 123456;
PostMessageIntTestCallback = function (msg)
{
assert.equal(expectedResult, msg, "Return result " + expectedResult);
asyncCallback();
};
CefSharp.PostMessage(expectedResult);
});
})();
</script>
</body>
</html>