我想在使用sinon存根之后使用sinon-test来清理我的测试。但我得到错误......
我该如何解决这个问题?
sinonTest.configureTest已弃用,将从中删除 未来版本的sinon-test中的公共API /Users/olejensen/WebstormProjects/SAM-api/node_modules/sinon-test/lib/test.js:67 抛出新的TypeError("期望的sinon对象"); ^
TypeError:期望的sinon对象 at Object.configure(/Users/olejensen/WebstormProjects/SAM-api/node_modules/sinon-test/lib/test.js:67:15) 在Function.sinonTest.configureTest(/Users/olejensen/WebstormProjects/SAM-api/node_modules/sinon-test/lib/index.js:18:17) 在对象。 (/Users/olejensen/WebstormProjects/SAM-api/test/unit/contract-provider/contracts-routes.spec.js:15:24) 在Module._compile(module.js:569:30) at Object.Module._extensions..js(module.js:580:10) 在Module.load(module.js:503:32) 在tryModuleLoad(module.js:466:12) 在Function.Module._load(module.js:458:3) 在Module.require(module.js:513:17) at require(internal / module.js:11:18) at /Users/olejensen/WebstormProjects/SAM-api/node_modules/mocha/lib/mocha.js:230:27 at Array.forEach(native) 在Mocha.loadFiles(/Users/olejensen/WebstormProjects/SAM-api/node_modules/mocha/lib/mocha.js:227:14) 在Mocha.run(/Users/olejensen/WebstormProjects/SAM-api/node_modules/mocha/lib/mocha.js:513:10) 在对象。 (/用户/ olejensen / WebstormProjects / SAM-API / node_modules /摩卡/ bin中/ _mocha:480:18) 在Module._compile(module.js:569:30) at Object.Module._extensions..js(module.js:580:10) 在Module.load(module.js:503:32) 在tryModuleLoad(module.js:466:12) 在Function.Module._load(module.js:458:3) 在Function.Module.runMain(module.js:605:10) 在启动时(bootstrap_node.js:158:16) 在bootstrap_node.js:575:3
contract.spec.ts
import * as chai from "chai";
import chaiDateTime = require('chai-datetime');
import * as sinon from "sinon";
import * as sinonTest from 'sinon-test';
import {ContractOption} from "../../../src/entity/ContractOption";
import {sumOptionsTotalPrice} from "../../../src/contract-provider/contracts-routes";
chai.use(chaiDateTime);
const expect = chai.expect;
const test = sinonTest.configureTest(sinon);
describe('Contracts-routes', function() {
describe("sumOptionsTotalPrice()", function() {
it("should return correct price with 2 options", test(function() {
// arrange
const opt1 = <any> sinon.createStubInstance(ContractOption);
opt1.price = 10;
const opt2 = <any> sinon.createStubInstance(ContractOption);
opt2.price = 20;
const options: ContractOption[] = [opt1, opt2];
// act
const actual = sumOptionsTotalPrice(options)
const expected = 30;
// assert
expect(actual).to.equal(expected)
}));
});
});
的package.json
"devDependencies": {
"@types/bcrypt": "^1.0.0",
"@types/body-parser": "^1.16.0",
"@types/chai": "^4.0.1",
"@types/chai-datetime": "0.0.30",
"@types/chai-spies": "0.0.0",
"@types/cors": "^2.8.0",
"@types/csv-parse": "^1.1.7",
"@types/csv-stringify": "^1.4.0",
"@types/express": "^4.0.35",
"@types/express-jwt": "0.0.34",
"@types/html-pdf": "^2.1.2",
"@types/jsonwebtoken": "^7.2.0",
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.12",
"@types/postmark": "^1.3.0",
"@types/sinon": "^2.3.3",
"@types/sinon-test": "^1.0.2",
"@types/stripe-node": "^4.6.7",
"chai": "^4.1.0",
"chai-datetime": "^1.5.0",
"chai-spies": "git+https://github.com/chaijs/chai-spies.git#master",
"mocha": "^3.4.2",
"reflect-metadata": "^0.1.9",
"sinon": "^3.0.0",
"sinon-test": "^2.0.0",
"swagger-parser": "^3.4.1",
"swagger2-ts-codegen": "2.5.0",
"tap-spec": "^4.1.1",
"typescript": "2.3.4",
"typings": "^2.1.1",
"walk-sync": "^0.3.1"
}