test: simplify tests

This commit is contained in:
Chi Vinh Le
2018-09-27 15:02:53 +02:00
parent d49a30c50a
commit 2e9d0a21fe
11 changed files with 36 additions and 47 deletions
@@ -1,3 +1,4 @@
import sinon from "sinon";
import timekeeper from "timekeeper";
import { timeout } from "talk-common/utils";
@@ -16,14 +17,8 @@ function createTestRenderer() {
.withArgs(undefined, { id: assets[0].id, url: null })
.returns(assets[0])
),
me: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(users[0])
),
settings: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
),
me: sinon.stub().returns(users[0]),
settings: sinon.stub().returns(settings),
},
Mutation: {
editComment: createSinonStub(
@@ -66,10 +66,7 @@ beforeEach(() => {
)
.returns(assetStub)
),
settings: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
),
settings: sinon.stub().returns(settings),
},
};
@@ -41,10 +41,7 @@ beforeEach(() => {
.withArgs(undefined, { id: assetStub.id, url: null })
.returns(assetStub)
),
settings: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
),
settings: sinon.stub().returns(settings),
},
};
@@ -1,4 +1,5 @@
import { ReactTestRenderer } from "react-test-renderer";
import sinon from "sinon";
import { timeout } from "talk-common/utils";
import { createSinonStub } from "talk-framework/testHelpers";
@@ -12,10 +13,7 @@ beforeEach(() => {
Query: {
comment: () => null,
asset: () => null,
settings: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
),
settings: sinon.stub().returns(settings),
},
};
@@ -38,10 +38,7 @@ beforeEach(() => {
.withArgs(undefined, { id: assetStub.id, url: null })
.returns(assetStub)
),
settings: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
),
settings: sinon.stub().returns(settings),
},
};
@@ -1,4 +1,5 @@
import { ReactTestRenderer } from "react-test-renderer";
import sinon from "sinon";
import timekeeper from "timekeeper";
import { timeout } from "talk-common/utils";
@@ -11,11 +12,14 @@ let testRenderer: ReactTestRenderer;
beforeEach(() => {
const resolvers = {
Query: {
asset: createSinonStub(s => s.throws(), s => s.returns(assets[0])),
me: createSinonStub(s => s.throws(), s => s.returns(users[0])),
settings: createSinonStub(
settings: sinon.stub().returns(settings),
me: sinon.stub().returns(users[0]),
asset: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
s =>
s
.withArgs(undefined, { id: assets[0].id, url: null })
.returns(assets[0])
),
},
Mutation: {
@@ -1,4 +1,5 @@
import { ReactTestRenderer } from "react-test-renderer";
import sinon from "sinon";
import timekeeper from "timekeeper";
import { timeout } from "talk-common/utils";
@@ -11,12 +12,15 @@ let testRenderer: ReactTestRenderer;
beforeEach(() => {
const resolvers = {
Query: {
settings: sinon.stub().returns(settings),
me: sinon.stub().returns(users[0]),
asset: createSinonStub(
s => s.throws(),
s => s.returns(assetWithDeepestReplies)
s =>
s
.withArgs(undefined, { id: assetWithDeepestReplies.id, url: null })
.returns(assetWithDeepestReplies)
),
me: createSinonStub(s => s.throws(), s => s.returns(users[0])),
settings: createSinonStub(s => s.returns(settings)),
},
Mutation: {
createComment: createSinonStub(
@@ -1,4 +1,5 @@
import { ReactTestRenderer } from "react-test-renderer";
import sinon from "sinon";
import timekeeper from "timekeeper";
import { timeout } from "talk-common/utils";
@@ -11,11 +12,14 @@ let testRenderer: ReactTestRenderer;
beforeEach(() => {
const resolvers = {
Query: {
asset: createSinonStub(s => s.throws(), s => s.returns(assets[0])),
me: createSinonStub(s => s.throws(), s => s.returns(users[0])),
settings: createSinonStub(
settings: sinon.stub().returns(settings),
me: sinon.stub().returns(users[0]),
asset: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
s =>
s
.withArgs(undefined, { id: assets[0].id, url: null })
.returns(assets[0])
),
},
Mutation: {
@@ -1,4 +1,5 @@
import { ReactTestRenderer } from "react-test-renderer";
import sinon from "sinon";
import { timeout } from "talk-common/utils";
import { createSinonStub } from "talk-framework/testHelpers";
@@ -17,10 +18,7 @@ beforeEach(() => {
.withArgs(undefined, { id: assetWithDeepReplies.id, url: null })
.returns(assetWithDeepReplies)
),
settings: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
),
settings: sinon.stub().returns(settings),
},
};
@@ -1,4 +1,5 @@
import { ReactTestRenderer } from "react-test-renderer";
import sinon from "sinon";
import { timeout } from "talk-common/utils";
import { createSinonStub } from "talk-framework/testHelpers";
@@ -17,10 +18,7 @@ beforeEach(() => {
.withArgs(undefined, { id: assets[0].id, url: null })
.returns(assets[0])
),
settings: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
),
settings: sinon.stub().returns(settings),
},
};
@@ -65,6 +65,7 @@ beforeEach(() => {
const resolvers = {
Query: {
settings: sinon.stub().returns(settings),
comment: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined, { id: commentStub.id }).returns(commentStub)
@@ -76,10 +77,6 @@ beforeEach(() => {
.withArgs(undefined, { id: assetStub.id, url: null })
.returns(assetStub)
),
settings: createSinonStub(
s => s.throws(),
s => s.withArgs(undefined).returns(settings)
),
},
};