Pulling in sinon submodules in browser with AMD and webpack

假装没事ソ 提交于 2019-12-24 00:38:41

问题


I'm running into the same problem described in this question. Basically sinon only pulls in all required submodules if you're using node. If you try to use it in the browser with AMD (I'm using webpack) apparently you have to manually include lib/spy.js.

I have a webpack module that currently exports sinon:

exports.sinon = require('sinon');

How would I modify that to roll in spy.js?

I think this is more of a CommonJS syntax question than anything.


回答1:


The following seems to work:

exports.sinon = require("sinon");
exports.sinon.spy = require("sinon/lib/sinon/spy");
exports.sinon.spyCall = require("sinon/lib/sinon/call");
exports.sinon.behavior = require("sinon/lib/sinon/behavior");
exports.sinon.stub = require("sinon/lib/sinon/stub");
exports.sinon.mock = require("sinon/lib/sinon/mock");
exports.sinon.collection = require("sinon/lib/sinon/collection");
exports.sinon.assert = require("sinon/lib/sinon/assert");
exports.sinon.sandbox = require("sinon/lib/sinon/sandbox");
exports.sinon.test = require("sinon/lib/sinon/test");
exports.sinon.testCase = require("sinon/lib/sinon/test_case");
exports.sinon.match = require("sinon/lib/sinon/match");

This is basically mimicking the behavior in sinon.js. If anyone has a better/cleaner solution please post it and I'll accept. And now that I look at it I wonder why there're



来源:https://stackoverflow.com/questions/25333595/pulling-in-sinon-submodules-in-browser-with-amd-and-webpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!