Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the --watch flag work again #2504

Merged
merged 3 commits into from Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/sinon/spy-formatters.js
Expand Up @@ -14,13 +14,14 @@ var slice = arrayProto.slice;

function colorSinonMatchText(matcher, calledArg, calledArgMessage) {
var calledArgumentMessage = calledArgMessage;
var matcherMessage = matcher.message;
if (!matcher.test(calledArg)) {
matcher.message = color.red(matcher.message);
matcherMessage = color.red(matcher.message);
if (calledArgumentMessage) {
calledArgumentMessage = color.green(calledArgumentMessage);
}
}
return `${calledArgumentMessage} ${matcher.message}`;
return `${calledArgumentMessage} ${matcherMessage}`;
}

function colorDiffText(diff) {
Expand Down
32 changes: 27 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -75,7 +75,7 @@
"dependencies": {
"@sinonjs/commons": "^3.0.0",
"@sinonjs/fake-timers": "^10.0.2",
"@sinonjs/samsam": "^7.0.1",
"@sinonjs/samsam": "^8.0.0",
"diff": "^5.1.0",
"nise": "^5.1.4",
"supports-color": "^7.2.0"
Expand Down
21 changes: 21 additions & 0 deletions test/spy-formatters-test.js
@@ -0,0 +1,21 @@
"use strict";
const { D } = require("./../lib/sinon/spy-formatters");
const sinon = require("../lib/sinon");
const { assert } = require("@sinonjs/referee");

describe('formatter specifier "D"', function () {
it("should not mutate matchers passed as arguments", function () {
const matcher = sinon.match(function test() {
return false;
}, "something");
assert.equals(matcher.message, "something");

const stub = sinon.stub();

stub(1, 2, 3);
/* eslint-disable new-cap */
D(stub, [matcher]);

assert.equals(matcher.message, "something");
});
});
15 changes: 8 additions & 7 deletions test/stub-test.js
Expand Up @@ -173,6 +173,7 @@ describe("stub", function () {
test: func,
};
func.aProp = 42;

createStub(object, "test");

assert.equals(object.test.aProp, 42);
Expand Down Expand Up @@ -1535,16 +1536,16 @@ describe("stub", function () {
});

it("stubs methods of function", function () {
var func = function () {
return;
};
class FunctionType extends Function {
func2() {
return 42;
}
}

var func = new FunctionType();
func.func1 = function () {
return;
};
// eslint-disable-next-line no-proto
func.__proto__.func2 = function () {
return;
};

createStub(func);

Expand Down