test: add test-utils (#333)

This commit is contained in:
Christoffer Åström
2020-02-28 09:08:21 +01:00
committed by GitHub
parent 02b063cab1
commit 4af3a40672
2 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
describe('test-utils', () => {
let sandbox;
let create;
let hook;
let hooked;
before(() => {
sandbox = sinon.createSandbox();
hooked = {
__hooked: true,
fn: sandbox.stub(),
initiate: sandbox.stub(),
run: sandbox.stub(),
teardown: sandbox.stub(),
runSnaps: sandbox.stub(),
observeActions: sandbox.stub(),
getImperativeHandle: sandbox.stub(),
updateRectOnNextRun: sandbox.stub(),
};
hook = sandbox.stub().returns(hooked);
[{ create }] = aw.mock([['@nebula.js/supernova', () => ({ hook })]], ['../index']);
});
afterEach(() => {
sandbox.restore();
});
it('should return api', () => {
const c = create();
expect(c.update).to.be.a('function');
expect(c.unmount).to.be.a('function');
expect(c.takeSnapshot).to.be.a('function');
expect(c.actions).to.be.a('function');
});
it('should update', () => {
const c = create();
c.update();
expect(hooked.run.callCount).to.equal(1);
hooked.run.reset();
const translator = {};
const context = { translator };
c.update(context);
expect(hooked.run).to.have.been.calledWithExactly(
sinon.match({
context,
})
);
});
it('should update', () => {
const c = create();
c.unmount();
expect(hooked.teardown.callCount).to.equal(1);
});
it('should take snapshot', () => {
const c = create();
c.takeSnapshot();
expect(hooked.runSnaps.callCount).to.equal(1);
});
it('should do actions', () => {
const c = create();
expect(c.actions()).to.have.length(0);
});
});

View File

@@ -9,6 +9,7 @@ module.exports = {
'**/__stories__/**',
'**/apis/supernova/index.js',
'**/apis/nucleus/index.js',
'**/apis/test-utils/index.js',
'**/packages/ui/icons/**/*.js', // Exclude the defined icons but test the `<SvgIcon />`
],
},