Skip to content

Commit

Permalink
Add jest
Browse files Browse the repository at this point in the history
  • Loading branch information
kozhevnikov-peter committed Mar 18, 2019
1 parent f4842d7 commit 7f78f73
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 13 deletions.
3 changes: 2 additions & 1 deletion config/jest.config.integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"rootDir": "../src",
"testMatch": ["**/*.test.int.js", "**/*.test.int.ts"],
"moduleFileExtensions": ["js", "ts", "json", "node"],
"testURL": "http://localhost/"
"testURL": "http://localhost/",
"setupFilesAfterEnv": ["../config/jest.extentions.js"]
}
3 changes: 2 additions & 1 deletion config/jest.config.integration.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"rootDir": "../src",
"testMatch": ["**/*.test.int.testnet.js", "**/*.test.int.testnet.ts"],
"moduleFileExtensions": ["js", "ts", "json", "node"],
"testURL": "http://localhost/"
"testURL": "http://localhost/",
"setupFilesAfterEnv": ["../config/jest.extentions.js"]
}
3 changes: 2 additions & 1 deletion config/jest.config.unit.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"rootDir": "../src",
"testMatch": ["**/*.test.js", "**/*.test.ts"],
"testURL": "http://localhost/",
"moduleFileExtensions": ["js", "ts", "json", "node"]
"moduleFileExtensions": ["js", "ts", "json", "node"],
"setupFilesAfterEnv": ["../config/jest.extentions.js"]
}
45 changes: 45 additions & 0 deletions config/jest.extentions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const Maybe = require('folktale/maybe');

expect.extend({
toBeNothing(maybe) {
if (Maybe.hasInstance(maybe)) {
return maybe.matchWith({
Just: () => ({
message: () => `${maybe} should to be instance of Maybe.Nothing`,
pass: false,
}),
Nothing: () => ({
message: () => `${maybe} is instance of Maybe.Nothing`,
pass: true,
}),
});
} else {
return {
message: () => `${maybe} should to be instance of Maybe`,
pass: false,
};
}
},
toBeJust(maybe, expected) {
if (Maybe.hasInstance(maybe)) {
return maybe.matchWith({
Just: ({ value }) => ({
message: () =>
`${maybe} is ${
value === expected ? '' : 'not'
} equal to ${expected}`,
pass: value == expected,
}),
Nothing: () => ({
message: () => `${maybe} should to be instance of Maybe.Just`,
pass: false,
}),
});
} else {
return {
message: () => `${maybe} should to be instance of Maybe`,
pass: false,
};
}
},
});
9 changes: 9 additions & 0 deletions src/@types/jest/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare namespace jest {
interface Matchers<R> {
toBeJust: <T>(m: Maybe<T>) => object;
}

interface Expect {
toBeJust: <T>(m: Maybe<T>) => object;
}
}
20 changes: 12 additions & 8 deletions src/services/presets/pg/getById/__test__/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ describe('getById', () => {
.run()
.listen({
onResolved: x =>
x.matchWith({
Just: ({ value }) => {
expect(value.__type).toBe('test');
done();
},
Nothing: () => {
throw `Can't get response from Maybe`;
},
expect(x).toBeJust({
data: 'someidgoeshere2942415',
__type: 'test',
}),
// x.matchWith({
// Just: ({ value }) => {
// expect(value.__type).toBe('test');
// done();
// },
// Nothing: () => {
// throw `Can't get response from Maybe`;
// },
// }),
}));
});

Expand Down
4 changes: 2 additions & 2 deletions src/services/transactions/__test__/integration/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const get = (service, txId) =>
.run()
.promise()
.then(x => {
expect(x.getOrElse(null)).toMatchSnapshot();
expect(x.unsafeGet()).toMatchSnapshot();
done();
})
.catch(e => done(JSON.stringify(e)));
Expand All @@ -27,7 +27,7 @@ const get = (service, txId) =>
.get('UNREAL')
.run()
.promise();
expect(tx.getOrElse(null)).toEqual(null);
expect(tx).toBeNothing();
},
TIMEOUT
);
Expand Down

0 comments on commit 7f78f73

Please sign in to comment.