This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add some basic tests with Jest (#5)
* tests: Add some basic tests with Jest Check the methods are called with the correct params * chore: Remove redundant build from CircleCI config Install deps if no cache before testing
- Loading branch information
Showing
7 changed files
with
2,119 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["env"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.babelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Nautic from '../index' | ||
|
||
export default class NauticConsumer { | ||
constructor() { | ||
this.nautic = new Nautic() | ||
} | ||
|
||
createNewContact() { | ||
this.nautic.createContact({ | ||
body: { | ||
name: 'Ron Swanson' | ||
} | ||
}) | ||
} | ||
|
||
findRonSwansonContact() { | ||
this.nautic.findContact({ param: 'name', value: 'Ron Swanson' }) | ||
} | ||
|
||
updateRonSwansonContact() { | ||
this.nautic.updateContact({ id: '1', company: 'Pawnee City Council' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Nautic from '../index' | ||
import NauticConsumer from './nautic-consumer' | ||
|
||
jest.mock('../index') | ||
|
||
beforeEach(() => { | ||
Nautic.mockClear() | ||
}) | ||
|
||
it('Check if the consumer called the createContact method on the class instance', () => { | ||
expect(Nautic).not.toHaveBeenCalled() | ||
|
||
const nauticConsumer = new NauticConsumer() | ||
expect(Nautic).toHaveBeenCalledTimes(1) | ||
|
||
nauticConsumer.createNewContact() | ||
|
||
const [mockNauticInstance] = Nautic.mock.instances | ||
const mockCreateContact = mockNauticInstance.createContact | ||
|
||
expect(mockCreateContact).toHaveBeenCalledWith({ | ||
body: { name: 'Ron Swanson' } | ||
}) | ||
expect(mockCreateContact).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('Check if the consumer called the findContact method on the class instance', () => { | ||
expect(Nautic).not.toHaveBeenCalled() | ||
|
||
const nauticConsumer = new NauticConsumer() | ||
expect(Nautic).toHaveBeenCalledTimes(1) | ||
|
||
nauticConsumer.findRonSwansonContact() | ||
|
||
const [mockNauticInstance] = Nautic.mock.instances | ||
const mockFindContact = mockNauticInstance.findContact | ||
|
||
expect(mockFindContact).toHaveBeenCalledWith({ | ||
param: 'name', | ||
value: 'Ron Swanson' | ||
}) | ||
expect(mockFindContact).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('Check if the consumer called the updateContact method on the class instance', () => { | ||
expect(Nautic).not.toHaveBeenCalled() | ||
|
||
const nauticConsumer = new NauticConsumer() | ||
expect(Nautic).toHaveBeenCalledTimes(1) | ||
|
||
nauticConsumer.updateRonSwansonContact() | ||
|
||
const [mockNauticInstance] = Nautic.mock.instances | ||
const mockUpdateContact = mockNauticInstance.updateContact | ||
|
||
expect(mockUpdateContact).toHaveBeenCalledWith({ | ||
id: '1', | ||
company: 'Pawnee City Council' | ||
}) | ||
expect(mockUpdateContact).toHaveBeenCalledTimes(1) | ||
}) |
Oops, something went wrong.