Skip to content

Commit

Permalink
test(module): Update test for browser & worker module (naver#3391)
Browse files Browse the repository at this point in the history
Reinforce test codes

Ref naver#3333
  • Loading branch information
netil authored Aug 30, 2023
1 parent fb7743c commit 17f9f00
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions test/module/module-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {expect} from "chai";
import sinon from "sinon";
import util from "../assets/util";
import {getGlobal, getFallback} from "../../src/module/browser";
import {getWorker} from "../../src/module/worker";
import {getWorker, runWorker} from "../../src/module/worker";

describe("MODULE", function() {
let chart;
Expand Down Expand Up @@ -71,12 +71,20 @@ describe("MODULE", function() {

describe("Browser", () => {
it("check global & fallback returns correctly when no default param is given.", () => {
// set nullish value for test
globalThis = global = self = null;
// test for global global
global = self = window;

// will return from 'global'
globalThis = null;
expect(getGlobal().document).to.be.ok;

const win = getGlobal();
// will return from 'self'
global = null;
expect(getGlobal().document).to.be.ok;

expect(win.document).to.be.ok;
// will return from Function('return this')()
self = null;
expect(getGlobal().document).to.be.ok;

// restore global
globalThis = global = self = window;
Expand Down Expand Up @@ -119,6 +127,34 @@ describe("MODULE", function() {
expect(errorStub.called).to.be.true;

errorStub.restore();

const error = console.error;

console.error = null;
const logStub = sinon.stub(console, "log");

worker.onerror({e: {message: "ERR MSG"}});

expect(logStub.called).to.be.true;

logStub.restore();
console.error = error;
});

it("check with dependency function", done => {
function depsFn() {
return 1234;
}

runWorker(
true,
function() { return depsFn(); },
function(res) {
expect(res).to.be.equal(1234);
done();
},
[depsFn]
)();
})
});
});

0 comments on commit 17f9f00

Please sign in to comment.