Skip to content

Commit

Permalink
upgrade jest to fix .js file coverage issue jestjs/jest#5109
Browse files Browse the repository at this point in the history
  • Loading branch information
eezhal92 committed Jan 7, 2018
1 parent 686dedc commit f8c91ff
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 162 deletions.
5 changes: 4 additions & 1 deletion app/controllers/__tests__/onboarding-controller.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { UnprocessableEntityError } from 'app/lib/errors';

import { OnBoardingController } from '../onboarding-controller';

describe('app/controllers/onboarding-controller', () => {
const next = jest.fn();
const request = {
session: jest.fn(),
user: jest.fn(),
flash: () => [],
csrfToken: jest.fn(),
};
const response = {
Expand All @@ -26,7 +29,7 @@ describe('app/controllers/onboarding-controller', () => {
onboarding.createStoreForm(request, response);

expect(response.render).toBeCalledWith('onboarding/create-store', {
user: request.user, csrfToken: request.csrfToken(),
user: request.user, csrfToken: request.csrfToken(), error: new UnprocessableEntityError(),
});
expect(response.render).toHaveBeenCalledTimes(1);
});
Expand Down
13 changes: 12 additions & 1 deletion app/controllers/onboarding-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import autoBind from 'auto-bind';
import onBoardingService from 'app/services/onboarding';
import { UnprocessableEntityError } from 'app/lib/errors';

export class OnBoardingController {
/**
Expand All @@ -23,7 +24,17 @@ export class OnBoardingController {
* @return {Express.Response}
*/
createStoreForm(request, response) {
const data = { user: request.user, csrfToken: request.csrfToken() };
// todo: need to be extracted into separate function
const inputError = new UnprocessableEntityError(
request.flash('errors')[0],
request.flash('oldInputs')[0],
);

const data = {
user: request.user,
csrfToken: request.csrfToken(),
error: inputError,
};

response.render('onboarding/create-store', data);
}
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ module.exports = {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest',
},
mapCoverage: true,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"eslint-plugin-react": "^7.5.1",
"eslint-plugin-vue": "^2.1.0",
"husky": "^0.14.3",
"jest": "^22.0.0",
"jest": "22.0.4",
"laravel-mix": "^1.7.2",
"nightwatch": "^0.9.19",
"nodemon": "^1.12.1",
Expand Down
9 changes: 9 additions & 0 deletions view/onboarding/create-store.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,23 @@
<div class="mb-2">
<label class="block mb-2" for="name">Nama Toko</label>
<input class="block p-1 border border-grey w-full" id="name" type="text" name="name" placeholder="Toko Keren">
<% if (error.getMessage('name')) { %>
<div class="text-red"><small><%= error.getMessage('name') %></small></div>
<% } %>
</div>
<div class="mb-2">
<label class="block mb-2" for="location">Lokasi</label>
<input class="block p-1 border border-grey w-full" id="location" type="text" name="location" placeholder="Palu, Sulteng">
<% if (error.getMessage('location')) { %>
<div class="text-red"><small><%= error.getMessage('location') %></small></div>
<% } %>
</div>
<div class="mb-2">
<label class="block mb-2" for="address">Alamat</label>
<textarea class="block p-1 border border-grey w-full" id="address" name="address" cols="30" rows="3"></textarea>
<% if (error.getMessage('address')) { %>
<div class="text-red"><small><%= error.getMessage('address') %></small></div>
<% } %>
</div>
<button id="submit" class="border border-blue p-2 rounded text-white bg-blue text-center text-white float-right" type="submit">Buat toko</button>
</form>
Expand Down
Loading

0 comments on commit f8c91ff

Please sign in to comment.