@@ -57,31 +57,28 @@ Removes option to pass a custom formatter.
57
57
## Sinon 7
58
58
59
59
For users upgrading to Sinon 7 the only known breaking API change is that
60
- ** negative ticks** are not allowed in ` Sinon @7` due to updating to lolex 3
60
+ ** negative ticks** are not allowed in ` sinon @7` due to updating to lolex 3
61
61
internally. This means you cannot use negative values in
62
- sinon.useFakeTimers().tick();
62
+ ` sinon.useFakeTimers().tick() ` ;
63
63
64
- If you experience any issues moving from Sinon 6 to Sinon 7, please let us
65
- know! https://github.com/sinonjs/sinon/issues/new?template=Bug_report.md .
64
+ If you experience any issues moving from Sinon 6 to Sinon 7, please
65
+ [ let us know ] ( https://github.com/sinonjs/sinon/issues/new?template=Bug_report.md ) !
66
66
67
67
## Sinon 6
68
68
69
69
There should be no reason for any code changes with the new Sinon 6.
70
70
Usually, ` MAJOR ` releases should come with breaking changes, but there are
71
71
no known breaking changes in ` sinon@6 ` at the time of this writing. We chose
72
- to release a new major version as a pragmatic solution to some noise related
73
- to releasing Sinon 5.1 https://github.com/sinonjs/sinon/pull/1829#issue-
74
- 193284761, which featured some breaking changes related to ESM (which since
72
+ to release a new major version as a [ pragmatic solution to some noise related to releasing Sinon 5.1] ( https://github.com/sinonjs/sinon/pull/1829#issue-193284761 ) ,
73
+ which featured some breaking changes related to ESM (which since
75
74
has been resolved).
76
75
77
76
If you should experience any issues moving from Sinon 5 to Sinon 6, please
78
- let us know!
79
- https://github.com/sinonjs/sinon/issues/new?template=Bug_report.md .
77
+ [ let us know] ( https://github.com/sinonjs/sinon/issues/new?template=Bug_report.md ) !
80
78
81
79
## Sinon 5
82
80
83
- As with all ` MAJOR ` releases in semver http://semver.org/ , there are
84
- breaking changes in ` sinon@5 ` .
81
+ As with all ` MAJOR ` releases in [ semver] ( http://semver.org/ ) , there are breaking changes in ` sinon@5 ` .
85
82
This guide will walk you through those changes.
86
83
87
84
## ` spy.reset() ` is removed, use ` spy.resetHistory() `
@@ -108,63 +105,67 @@ Now would be a good opportunity to tidy up your tests.
108
105
In earlier versions, you would manually have to create sandboxes and keep
109
106
references to them in order to restore them.
110
107
108
+ ``` js
111
109
const sandbox = sinon .createSandbox ();
112
110
113
111
describe (" myFunction" , function () {
114
- afterEach(function () {
115
- sandbox.restore();
116
- });
112
+ afterEach (function () {
113
+ sandbox .restore ();
114
+ });
117
115
118
- it("should make pie");
116
+ it (" should make pie" );
119
117
});
118
+ ```
120
119
121
120
122
121
122
+ ``` js
123
123
describe (" myFunction" , function () {
124
- afterEach(function () {
125
- sinon.restore();
126
- });
124
+ afterEach (function () {
125
+ sinon .restore ();
126
+ });
127
127
128
- it("should make pie");
128
+ it (" should make pie" );
129
129
});
130
+ ```
130
131
131
132
## Sinon 4
132
133
133
- As with all ` MAJOR ` releases in semver http://semver.org/ , there are
134
- breaking changes in ` sinon@4 ` .
134
+ As with all ` MAJOR ` releases in [ semver] ( http://semver.org/ ) , there are breaking changes in ` sinon@4 ` .
135
135
This guide will walk you through those changes.
136
136
137
137
## ` sinon.stub(obj, 'nonExistingProperty') ` - Throws
138
138
139
- Trying to stub a non-existing property will now fail, to ensure you are
140
- creating
141
- less error-prone tests https://github.com/sinonjs/sinon/pull/1557 .
139
+ Trying to stub a non-existing property will now fail, to ensure you are creating
140
+ [ less error-prone tests] ( https://github.com/sinonjs/sinon/pull/1557 ) .
142
141
143
142
## Sinon 3
144
143
145
- As with all ` MAJOR ` releases in semver http://semver.org/ , there are
144
+ As with all ` MAJOR ` releases in [ semver] ( http://semver.org/ ) , there are
146
145
breaking changes in ` sinon@3 ` .
147
146
This guide will walk you through those changes.
148
147
149
148
## ` sinon.stub(object, "method", func) ` - Removed
150
149
151
150
Please use ` sinon.stub(obj, "method").callsFake(func) ` instead.
152
151
152
+ ``` js
153
153
var stub = sinon .stub (obj, " stubbedMethod" ).callsFake (function () {
154
- return 42;
154
+ return 42 ;
155
155
});
156
+ ```
156
157
157
- A codemod is available https://github.com/hurrymaplelad/sinon-codemod to
158
+ A [ codemod is available] ( https://github.com/hurrymaplelad/sinon-codemod ) to
158
159
upgrade your code
159
160
160
161
## ` sinon.stub(object, property, value) ` - Removed
161
162
162
163
Calling ` sinon.stub ` with three arguments will throw an Error. This was
163
- deprecated with ` sinon@2 ` and has been removed with ` sinon@3 `
164
+ deprecated with ` sinon@2 ` and has been removed with ` sinon@3 ` .
164
165
165
166
## ` sinon.useFakeTimers([now, ]prop1, prop2, ...) ` - Removed
166
167
167
- ` sinon.useFakeTimers() ` signature has changed
168
+ ` sinon.useFakeTimers() ` signature has changed.
168
169
To define which methods to fake,
169
170
please use ` config.toFake ` . Other options are now available when configuring
170
171
` useFakeTimers ` . Please consult the documentation for more information.
@@ -174,15 +175,13 @@ please use `config.toFake`. Other options are now available when configuring
174
175
The changes in configuration for fake timers implicitly affect sandbox creation.
175
176
If your config used to look
176
177
like ` { useFaketimers: ["setTimeout", "setInterval"]} ` , you
177
- will now need to change it to `{ useFaketimers: { toFake: [ "setTimeout",
178
- "setInterval"] }}`.
178
+ will now need to change it to ` { useFaketimers: { toFake: ["setTimeout", "setInterval"] }} ` .
179
179
180
180
## ` sandbox.stub(obj, 'nonExistingProperty') ` - Throws
181
181
182
182
Trying to stub a non-existing property will now fail to ensure you are
183
183
creating
184
- less error-prone tests
185
- https://github.com/sinonjs/sinon/issues/1537#issuecomment-323948482 .
184
+ [ less error-prone tests] ( https://github.com/sinonjs/sinon/issues/1537#issuecomment-323948482 ) .
186
185
187
186
## Removal of internal helpers
188
187
@@ -224,36 +223,39 @@ configure `FakeServer`, `FakeXMLHttpRequest` and `FakeXDomainRequest`; these
224
223
three functions now allow the logger to be configured on a per-use basis. In
225
224
v1.x you may have written:
226
225
226
+ ``` js
227
227
sinon .log = function (msg ) { // your logging impl };
228
+ ` ` `
228
229
229
230
You would now individually import and configure the utility upon creation:
230
231
232
+ ` ` ` js
231
233
var sinon = require (" sinon" );
232
234
233
235
var myFakeServer = sinon .fakeServer .create ({
234
- logger: function (msg) { // your logging impl }
236
+ logger : function (msg ) { // your logging impl }
235
237
});
238
+ ` ` `
236
239
237
240
## sinon.test, sinon.testCase and sinon.config Removed
238
241
239
242
` sinon .test ` and ` sinon .testCase ` have been extracted from the Sinon API and
240
- moved into their own node module, sinon-test
241
- https://www.npmjs.com/package/sinon-test . Please refer to the sinon-test
242
- README https://github.com/sinonjs/sinon-test/blob/master/README.md for
243
- migration examples.
243
+ moved into their own node module, [sinon-test](https://www.npmjs.com/package/sinon-test).
244
+ Please refer to the [sinon-test README](https://github.com/sinonjs/sinon-test/blob/master/README.md) for migration examples.
244
245
245
246
## stub.callsFake replaces stub(obj, 'meth', fn)
246
247
247
248
` sinon .stub (obj, ' meth' , fn)` return a spy, not a full stub. Behavior could
248
249
not be redefined. ` stub .callsFake `
249
- now returns a full stub. Here's a codemod script
250
- https://github.com/hurrymaplelad/sinon-codemod to help you migrate.
251
- See discussion https://github.com/sinonjs/sinon/pull/823 .
250
+ now returns a full stub. Here's a [codemod script](https://github.com/hurrymaplelad/sinon-codemod) to help you migrate.
251
+ See [discussion](https://github.com/sinonjs/sinon/pull/823).
252
252
253
+ ` ` ` js
253
254
// Old
254
255
sinon .stub (obj, " meth" , fn);
255
256
// New
256
257
sinon .stub (obj, " meth" ).callsFake (fn);
258
+ ` ` `
257
259
258
260
## stub.resetHistory replaces stub.reset
259
261
@@ -262,10 +264,12 @@ Previously `stub.reset()` only reset the history of the stub. Stubs now have
262
264
separate methods for resetting the history and the behaviour. To mimic the
263
265
old behaviour replace all ` stub .reset ()` calls with ` stub .resetHistory ()` .
264
266
267
+ ` ` ` js
265
268
// Old
266
269
stub .reset ();
267
270
// New
268
271
stub .resetHistory ();
272
+ ` ` `
269
273
270
274
## Deprecation of internal helpers
271
275
0 commit comments