Skip to content

Commit

Permalink
[tests] use jest mocks instead of sinon ones for timers
Browse files Browse the repository at this point in the history
Instead of using jest faketimers that don't seem to work directly, (maybe
because jestjs/jest#3465) just mock `_.throttle`
to make it return the throttled function directly.
  • Loading branch information
adimasci authored and vdestraitt committed Jul 29, 2019
1 parent 0134973 commit b9ce0cc
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions tests/unit/popover.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash';
import sinon from 'sinon';
import { mount, Wrapper } from '@vue/test-utils';
import Vue from 'vue';

Expand Down Expand Up @@ -149,9 +148,9 @@ describe('DOM Position Tests', () => {
});

describe('Popover', function() {
var wrapper: Wrapper<Vue>;
var popoverWrapper: Wrapper<Vue>;
var clock = sinon.useFakeTimers();
let wrapper: Wrapper<Vue>;
let popoverWrapper: Wrapper<Vue>;
let throttleSpy: jest.SpyInstance<Function>;

const createWrapper = (...args: any) => {
const val = args[0],
Expand Down Expand Up @@ -200,17 +199,15 @@ describe('Popover', function() {
},
);
popoverWrapper = wrapper.find({ ref: 'popover' });
// Force throttle end
clock.tick(16);
};

beforeEach(function() {
clock = sinon.useFakeTimers();
throttleSpy = jest.spyOn(_, 'throttle').mockImplementation((fn: any) => fn);
});

afterEach(function() {
wrapper.destroy();
clock.restore();
throttleSpy.mockRestore();
});

it('should instanciate a popover', function() {
Expand Down

0 comments on commit b9ce0cc

Please sign in to comment.