describe('#inspect', () => { it('should throw an error if inspect fails', () => { // We need this chain of stubs to send our call down an explicit line that // will eventually throw a solid exception. let bogusContainer = dummyContainer(); const inspectStub = sinon.stub(bogusContainer, 'inspect').throws(); const stub = sinon.stub(landerode, 'getContainer').returns(bogusContainer); // Throw needs a function to check rather than a function result const cptPhasma = () => landerode.inspect('fn-2187'); expect(cptPhasma).to.throw(); inspectStub.restore(); stub.restore(); }); });
it('should throw an error', async () => { const stateManager = new StateManager(); const device = { setValue: fake.resolves(null), }; const sceneManager = new SceneManager(stateManager, event, device); expect(() => { sceneManager.checkTrigger({ type: 'one-unknown-event', device_feature: 'light-1', last_value: 12, }); }).to.throw(Error, 'Trigger type "one-unknown-event" has no checker function.'); });
describe("constructor", () => { it("should require logProvider", () => { options.logProvider = undefined; expect(() => { new StreamView(options); // eslint-disable-line no-new }).to.throw("StreamView requires logProvider"); }); it("should create a log node and listen for given events", () => { const streamView = new StreamView(options); expect(streamView).to.have.property("node").that.is.an.instanceof(blessed.log); expect(streamView.node).to.have.nested.property("options.label", " stdout / stderr "); expect(testContainer.screen.on).to.have.been .calledWithExactly("stdout", sinon.match.func) .and.calledWithExactly("stderr", sinon.match.func); }); });
describe('Device.getBySelector', () => { it('should return device', () => { const stateManager = new StateManager(event); stateManager.setState('device', 'test-device', { name: 'test', }); const device = new Device(event, {}, stateManager, {}); const oneDevice = device.getBySelector('test-device'); expect(oneDevice).to.deep.equal({ name: 'test', }); }); it('should return device', () => { const stateManager = new StateManager(event); stateManager.setState('device', 'test-device', { name: 'test', }); const device = new Device(event, {}, stateManager, {}); expect(() => device.getBySelector('not-found')).to.throw('Device not found'); }); });
describe("generate-layouts", () => { it("should validate default layout", () => { expect(generateLayouts("lib/default-layout-config.js")).to.be.an("array"); }); it("should fail on bad layouts", () => { expect(() => { generateLayouts("fake/layout-not-found"); }).to.throw(/Cannot find module/); expect(() => { mock("fake/invalid-config-layout", { invalid: "config" }); generateLayouts("fake/invalid-config-layout"); }).to.throw(/instance is not of a type\(s\) array/); }); it("should generate empty layout", () => { mock("fake/empty-layout", []); expect(generateLayouts("fake/empty-layout")).to.be.empty; }); it("should include a getPosition method", () => { const layout = generateLayouts("lib/default-layout-config.js"); const fake = { fake: "result" }; expect(layout[0]).to.respondTo("getPosition"); expect(layout[0].getPosition(fake)).to.eql(fake); }); });
describe('#build', () => { it('should return the correct default options when not specified'); it('#build should return an object.', () => { const buildResult = compose.build( ['string1', 'string2'], 'my_project', myOpts ); expect(buildResult).to.be.an('object'); }); it('#build should throw and error if project string is not defined.', () => { expect(() => { compose.build( ['string test'], null, myOpts ); }).to.throw(Error); }); });