UNPKG

sinon-typed

Version:

Nicer stubbing in a TypeScript environment

71 lines 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sinon = require("sinon"); const chai_1 = require("chai"); const sinon_typed_1 = require("./sinon-typed"); describe('SinonTyped', () => { describe('mock', () => { it('methods', () => { const testMock = sinon_typed_1.SinonTyped.mock(); const expectation = testMock.control.expects('aMethod').withArgs('value1').once(); expectation.returns('result1'); const result = testMock.object.aMethod('value1'); chai_1.expect(result).to.equals('result1'); expectation.verify(); }); it('methods when on a sandbox', () => { const sandbox = sinon.createSandbox(); const testMock = sinon_typed_1.SinonTyped.mock(sandbox); const expectation = testMock.control.expects('aMethod').withArgs('value1').once(); expectation.returns('result1'); chai_1.expect(testMock.object.aMethod('value1')).to.equals('result1'); expectation.verify(); sandbox.restore(); chai_1.expect(testMock.object.aMethod('value1')).to.equals(undefined); }); }); describe('stub', () => { it('methods', () => { const testStub = sinon_typed_1.SinonTyped.stub(); const stubMethod1 = testStub.stubMethod('aMethod'); const stubMethod2 = testStub.stubMethod('aMethod'); stubMethod1.withArgs('value2').returns('result2'); stubMethod2.withArgs('value3').returns('result3'); chai_1.expect(stubMethod1).to.equals(stubMethod2); chai_1.expect(testStub.object.aMethod('value2')).to.equals('result2'); chai_1.expect(testStub.object.aMethod('value3')).to.equals('result3'); }); it('methods when on a sandbox', () => { const sandbox = sinon.createSandbox(); const testStub = sinon_typed_1.SinonTyped.stub(sandbox); testStub.stubMethod('aMethod') .withArgs('value2').returns('result2') .withArgs('value3').returns('result3'); chai_1.expect(testStub.object.aMethod('value2')).to.equals('result2'); chai_1.expect(testStub.object.aMethod('value3')).to.equals('result3'); sandbox.restore(); chai_1.expect(testStub.object.aMethod('value2')).to.equals(undefined); chai_1.expect(testStub.object.aMethod('value3')).to.equals(undefined); }); it('properties', () => { const testStub = sinon_typed_1.SinonTyped.stub(); testStub.stubProperty('aProperty').returns(42); chai_1.expect(testStub.object.aProperty).to.equals(42); }); it('properties when on a sandbox', () => { const sandbox = sinon.createSandbox(); const testStub = sinon_typed_1.SinonTyped.stub(sandbox); testStub.stubProperty('aProperty').returns(42); chai_1.expect(testStub.object.aProperty).to.equals(42); sandbox.restore(); chai_1.expect(testStub.object.aProperty).to.equals(undefined); }); }); describe('partially stub', () => { it('half-baked objects', () => { const test = sinon_typed_1.SinonTyped.partially({ aProperty: 100 }); chai_1.expect(test.aProperty).to.equals(100); }); }); }); //# sourceMappingURL=sinon-typed-spec.js.map