|
6 | 6 | } = require('../examples') |
7 | 7 |
|
8 | 8 | class SomeMessage {} |
| 9 | +class SomeClassWithCreate {} |
| 10 | +SomeClassWithCreate.create = (fields) => { |
| 11 | + const instance = new SomeClassWithCreate() |
| 12 | + instance.fields = fields |
| 13 | + return instance |
| 14 | +} |
9 | 15 |
|
10 | 16 | describe('follow', () => { |
11 | 17 | describe('metadata', () => { |
@@ -74,23 +80,44 @@ describe('follow', () => { |
74 | 80 | }) |
75 | 81 |
|
76 | 82 | describe('message class with create method', () => { |
77 | | - const SomeClassWithCreate = class {} |
78 | | - SomeClassWithCreate.create = () => { |
79 | | - return new SomeClassWithCreate() |
80 | | - } |
81 | | - |
82 | 83 | const previous = exampleMessage() |
83 | 84 | const next = follow(previous, SomeClassWithCreate) |
84 | 85 |
|
85 | 86 | it('no fields are copied', () => { |
86 | 87 | expect(next.someAttribute).toBeUndefined() |
87 | 88 | }) |
88 | 89 |
|
| 90 | + it('fields are supplied to create method', () => { |
| 91 | + expect(next.fields).toEqual(previous) |
| 92 | + }) |
| 93 | + |
89 | 94 | it('returns the created message instance', () => { |
90 | 95 | expect(next).toBeInstanceOf(SomeClassWithCreate) |
91 | 96 | }) |
92 | 97 | }) |
93 | 98 |
|
| 99 | + describe('additional fields', () => { |
| 100 | + describe('message class has no create method', () => { |
| 101 | + it('includes additional field', () => { |
| 102 | + const previous = exampleMessage() |
| 103 | + const additional = exampleRandomValue() |
| 104 | + const next = follow(previous, SomeMessage, { additional }) |
| 105 | + |
| 106 | + expect(next.additional).toEqual(additional) |
| 107 | + }) |
| 108 | + }) |
| 109 | + |
| 110 | + describe('message class has create method', () => { |
| 111 | + it('includes additional field', () => { |
| 112 | + const previous = exampleMessage() |
| 113 | + const additional = exampleRandomValue() |
| 114 | + const next = follow(previous, SomeClassWithCreate, { additional }) |
| 115 | + |
| 116 | + expect(next.fields.additional).toEqual(additional) |
| 117 | + }) |
| 118 | + }) |
| 119 | + }) |
| 120 | + |
94 | 121 | describe('message with no metadata', () => { |
95 | 122 | it('followed messages has new metadata ', () => { |
96 | 123 | const previous = exampleMessage() |
|
0 commit comments