Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bartos committed May 15, 2018
1 parent 7044f62 commit 265c7f8
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions test/unit/core-shim-test.js
Expand Up @@ -9,6 +9,20 @@ describe('CoreShim', function() {
core = new CoreShim(document.createElement('div'));
});

function expectError(expectedCode) {
sandbox.stub(core.setup, 'start').callsFake(() => Promise.reject({ message: 'foo', code: expectedCode }));
const expectError =
new Promise((resolve, reject) => {
core.on(SETUP_ERROR, e => resolve(e));
})
.then(e => {
expect(e.code).to.equal(expectedCode);
})

core.init({}, {});
return expectError;
}

it('is a constructor', function() {
expect(core).to.be.an('object');
});
Expand All @@ -19,41 +33,14 @@ describe('CoreShim', function() {
});

it('sets the setupError code to 100000 if passed an error with no code', function () {
sandbox.stub(core.setup, 'start').callsFake(() => Promise.reject({ message: 'foo' }));
const expectError = new Promise((resolve, reject) => {
core.on(SETUP_ERROR, e => resolve(e));
})
.then(e => {
expect(e.code).to.equal(100000);
})

core.init({}, {});
return expectError;
return expectError(100000);
});

it('sets the setupError code to 100000 if passed an error with a non-numerical code', function () {
sandbox.stub(core.setup, 'start').callsFake(() => Promise.reject({ message: 'foo', code: 'foo' }));
const expectError = new Promise((resolve, reject) => {
core.on(SETUP_ERROR, e => resolve(e));
})
.then(e => {
expect(e.code).to.equal(100000);
})

core.init({}, {});
return expectError;
return expectError(100000);
});

it('passes through a valid error code', function () {
sandbox.stub(core.setup, 'start').callsFake(() => Promise.reject({ message: 'foo', code: 424242 }));
const expectError = new Promise((resolve, reject) => {
core.on(SETUP_ERROR, e => resolve(e));
})
.then(e => {
expect(e.code).to.equal(424242);
})

core.init({}, {});
return expectError;
return expectError(424242);
});
});
});

0 comments on commit 265c7f8

Please sign in to comment.