Skip to content

Commit

Permalink
fix: incorrect formatting of message with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ctumolosus authored and BerkeleyTrue committed Feb 9, 2019
1 parent e480622 commit b188176
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions test/package/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ module.exports = function() {
warning(true, 'warning message');

expect(mockFn).toHaveBeenCalledTimes(1);
expect(calls[0][0])
.toEqual(expect.stringMatching(/warning: warning message/i));
expect(mockFn).toHaveBeenCalledWith('Warning: warning message');

// should format message with arguments
warning(false, 'warning %s with one argument', 'message');
warning(false, 'warning %s with %s arguments', 'message', 'two');

expect(mockFn).toHaveBeenCalledTimes(3);
expect(mockFn).toHaveBeenCalledWith('Warning: warning message with one argument');
expect(mockFn).toHaveBeenCalledWith('Warning: warning message with two arguments');

console.error = error;
};
6 changes: 3 additions & 3 deletions warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ var warning = function() {};
if (__DEV__) {
var printWarning = function printWarning(format, args) {
var len = arguments.length;
args = new Array(len > 2 ? len - 2 : 0);
for (var key = 2; key < len; key++) {
args[key - 2] = arguments[key];
args = new Array(len > 1 ? len - 1 : 0);
for (var key = 1; key < len; key++) {
args[key - 1] = arguments[key];
}
var argIndex = 0;
var message = 'Warning: ' +
Expand Down

0 comments on commit b188176

Please sign in to comment.