sinon

How do I assert against objects with spies in Cypress?

久未见 提交于 2019-12-11 09:38:23
问题 I am using Cypress spies to test client-side analytics. My intent in this test is to confirm that identify has been called like so: identify('myemail@email.com', { groupId: 1002, groupName: "myGroup", someProp: 1, anotherProp: 2 }) I hook the spies into emitter events on a global analytics object in window:before:load (note the while loop is to deal with delays in the library loading): Cypress.on("window:before:load", async (win: Window) => { const sleep = (n = 1) => new Promise(r =>

sinonjs - advance clock to 59 minutes and wait for 1 minute actually

跟風遠走 提交于 2019-12-11 08:41:26
问题 I've a web component for auto-logout functionality which shows modal window with a message on 59th minute and stay for another minute in case of no activity. And logs out the user if user doesn't click anywhere on the window. So, no activity for an hour will logout the user automatically. This works fine. Now, to test this functionality, I tried to use sinonjs . I used FakeTimers but couldn't able to achieve the result. I am trying to test that modal window with message shows up. Here's the

Is there a way to run Ember.Testing acceptance tests with fake timers?

人走茶凉 提交于 2019-12-11 08:34:05
问题 I'm working on a project in EmberJS that has a set of acceptance tests (qUnit with EmberJS helpers). Now, I'm trying to optimize those tests as much as possible because waiting 10 minutes for every run is just not nice. Some tests that we have actually need to wait for some things to happen: a timer to run out, a minute to pass for the clocks to update, etc. I tried using sinonjs with faketimers, but this seems to mess up the ember run loop and any other usage of setInterval / setTimeout that

how to unit test controller which uses this.get('store')

若如初见. 提交于 2019-12-11 08:13:03
问题 I am unit testing my controller using mocha. My controller looks like: AS.MyController = Ember.ObjectController.extend(Ember.Validations.Mixin, { name: null, description: null, init: function () { this._super(); this.get('store').find('something'); }, .... }); And my test begins like: describe("MyControllerTest", function () { //tried but didn't work //delete AS.MyController.init; var controller = AS.MyController.create(); ..... }) and the browser always throws error on "this.get('store')"

Backbone collection fetch not populating in Jasmine + Sinon spec

我是研究僧i 提交于 2019-12-11 07:26:53
问题 When I run this spec output I get "Expected 0 to equal 2." 2 is the correct length of model objects in my fixture so Sinon's fakeServer is responding properly with the mocked response. I can't figure out why my Collection has zero objects after fetch then. Any help would be really appreciated! FYI: this is coming from following along the Backbone Sinon + Jasmine tutorial here: http://tinnedfruit.com/2011/03/25/testing-backbone-apps-with-jasmine-sinon-2.html Spec: describe "Todos collection",

Testing callbacks that are not called with Jest?

為{幸葍}努か 提交于 2019-12-11 07:20:16
问题 Is there a way to test that a callback is not called with Jest? For example: o.subscribe(cb, cbError, cbComplete); The cb and cbComplete callbacks should fire and the cbError callback should not fire. is there a way to test that cbError is never called? 回答1: Per @Richard's comment: let error = false; let cbError = ()=> { error =true }; let cbComplete = ()=>{ complete = true; expect(complete).toBeTruthy(); expect(error).toBeFalsy(); done(); //This is the async callback that Jest provides to

Node Stub a method that returns an object

老子叫甜甜 提交于 2019-12-11 05:29:53
问题 I have a module that has some properties. I am using it as below Var propmodule = require('me-props'); var prop = new propmodule('server'); prop.get('min); //returns 3 prop.get('max') //returns 10 I have to mock this for testing. Did the below code using proxyquire and sinon var spro = proxyquire('../lib/add.js',{ 'me-props' : sinon.stub.returns({ get : sinon.stub.returns({ min :'3', max : '10 )} )} }) The above code works. But while testing, the get method call returns an object. get(min)

Using sinon mocks with nodeunit

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:32:41
问题 I'm learning to use sinon with nodeunit, specifically to do mocking. The recommended approach is to use sinon-nodeunit. According to the documentation, mocks should be available via the mock method of the test parameter to each test function. However, this doesn't seem to work. If I run nodeunit on a file containing the following — require('sinon-nodeunit'); exports['test sinon-nodeunit'] = function (test) { mock = test.mock({}); test.done(); }; — I get this: $ nodeunit test/test-sinon

Stubbing virtual attributes of Mongoose model

强颜欢笑 提交于 2019-12-11 02:27:34
问题 Is there a way to stub a virtual attribute of a Mongoose Model? Assume Problem is a model class, and difficulty is a virtual attribute. delete Problem.prototype.difficulty returns false, and the attribute is still there, so I can't replace it with any value I want. I also tried var p = new Problem(); delete p.difficulty; p.difficulty = Problem.INT_EASY; It didn't work. Assigning undefined to Problem.prototype.difficulty or using sinon.stub(Problem.prototype, 'difficulty').returns(Problem.INT

How to test touch events using desktop browser?

匆匆过客 提交于 2019-12-11 01:57:40
问题 I want to write some test cases for touch events. In my code I have the following logic to decide whether it is on touch devices. if(document.documentElement.ontouchstart !== undefined) { //content that I want to write test cases about } Now I want to fake document.documentElement.ontouchstart not to be undefined , so the inside logic will be executed. I tried using Sinon.js 's stub to assign an empty function to document.documentElement.ontouchstart . But it will throw an error indication