Skip to content

Commit 0d373a4

Browse files
committed
fix(api) update update widgets tests
1 parent c51af25 commit 0d373a4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

api/actions/__tests__/widget-update-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {expect} from 'chai';
22
import update from '../widget/update';
3+
import * as load from '../widget/load';
34
import sinon from 'sinon';
45

56
describe('widget update', () => {
@@ -10,11 +11,22 @@ describe('widget update', () => {
1011
});
1112

1213
describe('randomly successful', () => {
14+
const widgets = [{}, {id: 2, color: 'Red'}];
15+
1316
beforeEach(()=> {
1417
sinon.stub(Math, 'random').returns(0.3);
1518
});
1619

20+
afterEach(()=> {
21+
if ('restore' in load.default) {
22+
load.default.restore();
23+
}
24+
});
25+
1726
it('does not accept green widgets', () => {
27+
sinon.stub(load, 'default').returns(new Promise((resolve) => {
28+
resolve(widgets);
29+
}));
1830
return update({session: {}, body: {color: 'Green'}}).
1931
then(
2032
()=> {
@@ -25,11 +37,15 @@ describe('widget update', () => {
2537
});
2638

2739
it('updates a widget', () => {
40+
sinon.stub(load, 'default').returns(new Promise((resolve) => {
41+
resolve(widgets);
42+
}));
2843
const widget = {id: 2, color: 'Blue'};
2944
return update({session: {}, body: widget}).
3045
then(
3146
(res)=> {
3247
expect(res).to.deep.equal(widget);
48+
expect(widgets[1]).to.deep.equal(widget);
3349
});
3450
});
3551
});

0 commit comments

Comments
 (0)