使用AMD和Webpack在浏览器中引入sinon子模块 [英] Pulling in sinon submodules in browser with AMD and webpack

查看:83
本文介绍了使用AMD和Webpack在浏览器中引入sinon子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了此问题中所述的相同问题问题.基本上,sinon仅在使用节点时才拉入所有必需的子模块.如果您尝试在带有AMD的浏览器中使用它(我正在使用Webpack),则显然必须手动添加lib/spy.js.

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.

我有一个webpack模块,当前可以导出sinon:

I have a webpack module that currently exports sinon:

exports.sinon = require('sinon');

我如何修改才能滚动到spy.js?

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

我认为这比任何其他问题都更是CommonJS语法问题.

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

推荐答案

以下似乎有效:

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");

这基本上是模仿sinon.js中的行为.如果有人有更好/更清洁的解决方案,请发布它,我会接受.现在,我看着它,我想知道为什么会有

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

这篇关于使用AMD和Webpack在浏览器中引入sinon子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆