Skip to content

Commit

Permalink
Update eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
blaumeise20 committed Jan 24, 2021
1 parent caf545e commit 858cd30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"quotes": ["error", "double"],
"indent": ["error", 4],
"semi": "error"
},
"env": {
"jest/globals": true
}
}
24 changes: 12 additions & 12 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const { Timeout, Interval } = require(".");
require('jest');
require("jest");

beforeEach(() => {
jest.useFakeTimers();
});

describe('state tests', () => {
test('state is set to 0 after creation of timer', () => {
describe("state tests", () => {
test("state is set to 0 after creation of timer", () => {
const to = new Timeout(() => { }, 0);
expect(to.state).toBe(0);
});

test('state is set to 1 when timer has been started', () => {
test("state is set to 1 when timer has been started", () => {
const waitTime = 1000;
const callback = jest.fn();
const to = new Timeout(callback, waitTime);
to.start();
expect(to.state).toBe(1);
});

test('state is set to 3 and callback is called after timer is completed', () => {
test("state is set to 3 and callback is called after timer is completed", () => {
const waitTime = 1000;
const callback = jest.fn();
const to = new Timeout(callback, waitTime);
Expand All @@ -32,35 +32,35 @@ describe('state tests', () => {
});
});

describe('time start tests', () => {
test('timeout is not started when autostart is false', () => {
describe("time start tests", () => {
test("timeout is not started when autostart is false", () => {
const to = new Timeout(() => { }, 0, false);
expect(setTimeout).toHaveBeenCalledTimes(0);
});

test('timeout is not started when autostart is not specified', () => {
test("timeout is not started when autostart is not specified", () => {
const to = new Timeout(() => { }, 0);
expect(setTimeout).toHaveBeenCalledTimes(0);
});

test('timeout is started when autostart is true', () => {
test("timeout is started when autostart is true", () => {
const waitTime = 1000;
const to = new Timeout(() => { }, waitTime, true);
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), waitTime);
});

test('interval is not started when autostart is false', () => {
test("interval is not started when autostart is false", () => {
const to = new Interval(() => to.stop(), 1, false);
expect(setInterval).toHaveBeenCalledTimes(0);
});

test('interval is not started when autostart is not specified', () => {
test("interval is not started when autostart is not specified", () => {
const to = new Interval(() => to.stop(), 1);
expect(setInterval).toHaveBeenCalledTimes(0);
});

test('interval is started when autostart is true', () => {
test("interval is started when autostart is true", () => {
const waitTime = 1000;
const to = new Interval(() => to.stop(), waitTime, true);
expect(setInterval).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit 858cd30

Please sign in to comment.