question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to run tests with sinon?

See original GitHub issue

Hi, I am trying to run a test package and noticing that webpack still seems to bundle things in node_modules even though I am using the following karma/webpack config: https://gist.github.com/fb66622fa8284c76e6d9

An example test file:

'use strict';

var React = require('react/addons');
//var sinon = require('sinon');

React gets bundled, without issue even though I’d think that excludes would ignore it. The issue is when I uncomment the sinon test, I get several critical issues:

WARNING in ./~/sinon/lib/sinon.js
Critical dependencies:
39:25-32 require function is used in a way, in which dependencies cannot be statically extracted
 @ ./~/sinon/lib/sinon.js 39:25-32

WARNING in ./~/sinon/lib/sinon/behavior.js
Critical dependencies:
353:25-32 require function is used in a way, in which dependencies cannot be statically extracted
 @ ./~/sinon/lib/sinon/behavior.js 353:25-32

Am I just doing things wrong by expecting mocha tests to run like they would on the server?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ColChcommented, Feb 17, 2016

@josmardias use karma-sinon or karma-sinon-chai

If you need your unique setup, you can simple require sinon within webpack, and use modules: noparse: [ /sinon\.js/ ] within your webpack config (that worked for me). Documentation for module.noParse

1reaction
marrcommented, Mar 14, 2015

Thanks @ColCh I ended up doing that and its working great. Here’s an example if anyone wants to see it. https://github.com/bitwise/status

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sinon JS Tutorial: A Beginner's Guide To Mocking - Testim Blog
SinonJS is a JavaScript library that provides standalone test spies, stubs, and mocks. It's very flexible and easy to use since you can...
Read more >
Sinon.JS - Standalone test fakes, spies, stubs and mocks for ...
Standalone test spies, stubs and mocks for JavaScript. Works with any unit testing framework. · Get Started · Try It Out.
Read more >
Best Practices for Spies, Stubs and Mocks in Sinon.js
When you use spies, stubs or mocks, wrap your test function in sinon.test . This allows you to use Sinon's automatic clean-up functionality....
Read more >
Sinon Tutorial: JavaScript Testing with Mocks, Spies & Stubs
Put simply, Sinon allows you to replace the difficult parts of your tests with something that makes testing simple. When testing a piece...
Read more >
How to Write Unit Tests Using Sinon.js - YouTube
comIn this Sinon.js Tutorial, we give an overview of the Sinon.js l... ... Your browser can't play this video. Learn more. Switch camera....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found