8000 Merge pull request #25 from fbeline/factory-static-method · wolfwithcode/design-patterns-JS@98f83b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98f83b5

Browse files
authored
Merge pull request fbeline#25 from fbeline/factory-static-method
Factory static method
2 parents d0eedab + 8822cd0 commit 98f83b5

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/creational/factory/factory_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class BmwFactory {
22

3-
create(type) {
3+
static create(type) {
44
if (type === 'X5')
55
return new Bmw(type, 108000, 300);
66
if (type === 'X6')

test/factory_es6-test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
const expect = require('chai').expect;
22
import BmwFactory from '../src/creational/factory/factory_es6';
33

4-
describe('factory es6 test', () => {
5-
it('sanity', () => {
6-
const bmwFactory = new BmwFactory();
7-
const x5 = bmwFactory.create('X5');
8-
const x6 = bmwFactory.create('X6');
4+
describe('Factory es6 test', () => {
5+
it('We can create a X5 instance', () => {
6+
const x5 = BmwFactory.create('X5');
7+
expect(x5.model).to.equal('X5');
8+
});
99

10+
it('The X5 price is properly set', () => {
11+
const x5 = BmwFactory.create('X5');
1012
expect(x5.price).to.equal(108000);
11-
expect(x6.price).to.equal(111000);
12-
expect(x5.maxSpeed).to.equal(300);
13-
expect(x6.maxSpeed).to.equal(320);
1413
});
1514
});

0 commit comments

Comments
 (0)
0