Last active
December 17, 2015 13:39
-
-
Save juanghurtado/5618659 to your computer and use it in GitHub Desktop.
Sinon fake server making fixtures fail on another spec file!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define [ | |
'backbone' | |
'framework/entities/entities' | |
], (Backbone) -> | |
beforeEach -> | |
# Start the sandbox, telling it to use a fake server | |
@sandbox = sinon.sandbox.create() | |
@sandbox.useFakeServer() | |
afterEach -> | |
@sandbox.restore() # I'm restoring the sandbox, so the fake server is retored too! | |
describe "Sample spec", -> | |
it "using Sinon fake server is making my fixtures fail on other spec files :(", -> | |
# Sinon JS documentation tells to use sandbox.server, but it does not exist. | |
# I'm using sandbox.serverPrototype instead | |
@sandbox.serverPrototype.respondWith("GET", "/test", [ | |
200, | |
{ | |
"Content-Type": "application/json" | |
}, | |
'{}' | |
]) | |
# This is just a sample spec. I'm overwriting Backbone.sync method | |
# to add a _fetchPromise property on the entity on .fetch() | |
class Mock extends Backbone.Model | |
url: '/test' | |
mockEntity = new Mock | |
mockEntity.fetch() | |
should = require('chai').should() | |
should.exist mockEntity._fetchPromise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forget it. It's my fault.
beforeEach
andafterEach
blocks are not insidedescribe
, so they are global for all specs.So sorry.