nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: baianat/vee-validate
Pull request #737 (2017-08-17 15:06:12)

feat: errorbag new function firstNot
Usually, when we build up our mobile application, we don't want to show all of the error to users. 
The error from 'required' rule is useful for validating a form but also disturbing users, you know they can truly see which field is required from their little mobile phone. Only users type wrong characters we want to notice them. 

so, why not add a new function that filters all errors that not match the rule~


Patch:
diff --git a/src/errorBag.js b/src/errorBag.js
index c23660d4..ed5e544b 100644
--- a/src/errorBag.js
+++ b/src/errorBag.js
@@ -204,6 +204,17 @@ export default class ErrorBag {
 
     return (error && error.msg) || null;
   }
+  /**
+     * Gets the first error message for a specific field that not match the rule.
+     * @param {String} name The name of the field.
+     * @param {String} rule The name of the rule.
+     * @param {String} scope The name of the scope (optional).
+     */
+  firstNot (name, rule = 'required', scope) {
+    const error = this.collect(name, scope, false).filter(e => e.rule !== rule)[0];
+
+    return (error && error.msg) || null;
+  }
 
   /**
    * Removes errors by matching against the id.


Test patch:
diff --git a/tests/errorBag.js b/tests/errorBag.js
index d551f3af..c2b59aff 100644
--- a/tests/errorBag.js
+++ b/tests/errorBag.js
@@ -179,6 +179,20 @@ test('fetches the first error message for a specific field', () => {
   expect(errors.first('scope2.email:rule2')).toBe('mah');
 });
 
+test('fetches the first error message for a specific field that not match the rule', () => {
+  const errors = new ErrorBag();
+  errors.add('email', 'The email is required', 'required');
+
+  errors.add('email', 'The email is invalid', 'rule1');
+  errors.add('email', 'The email is shorter than 3 chars.', 'rule1');
+
+  errors.add('email', 'This is the third rule', 'rule2');
+  errors.add('email', 'This is the forth rule', 'rule2');
+
+  expect(errors.firstNot('email')).toBe('The email is invalid');
+  expect(errors.firstNot('email', 'rule1')).toBe('The email is required');
+});
+
 test('fetches the first error rule for a specific field', () => {
   const errors = new ErrorBag();
   errors.add('email', 'The email is invalid', 'rule1');
Repository: baianat/vee-validate
Pull request #934 (2017-10-31 20:17:27)

Implementation Two: Reset returns a promise
In response to issue #843 

This is another possible implementation where reset returns a promise. Reject is never called since a reset never fails, so the callback seems to be a better implementation


Patch:
diff --git a/src/core/validator.js b/src/core/validator.js
index 930c1a24..ed737aa8 100644
--- a/src/core/validator.js
+++ b/src/core/validator.js
@@ -26,7 +26,7 @@ export default class Validator {
   paused: boolean;
   ownerId: string | number;
   clean: () => void;
-  reset: () => void;
+  reset: () => Promise;
 
   constructor (validations?: MapObject, options?: MapObject = { vm: null, fastExit: true }) {
     this.strict = STRICT_MODE;
@@ -39,13 +39,19 @@ export default class Validator {
     this.ownerId = options.vm && options.vm._uid;
     // create it statically since we don't need constant access to the vm.
     this.reset = options.vm && isCallable(options.vm.$nextTick) ? () => {
-      options.vm.$nextTick(() => {
+      return new Promise((resolve, reject) => {
+        options.vm.$nextTick(() => {
+          this.fields.items.forEach(i => i.reset());
+          this.errors.clear();
+          resolve();
+        });
+      });
+    } : () => {
+      return new Promise((resolve, reject) => {
         this.fields.items.forEach(i => i.reset());
         this.errors.clear();
+        resolve();
       });
-    } : () => {
-      this.fields.items.forEach(i => i.reset());
-      this.errors.clear();
     };
     /* istanbul ignore next */
     this.clean = () => {


Test patch:
diff --git a/tests/validator.js b/tests/validator.js
index 6b7afff7..e1acf382 100644
--- a/tests/validator.js
+++ b/tests/validator.js
@@ -788,6 +788,25 @@ test('resets errors on the next tick if available', () => {
   v.reset();
   expect(vm.$nextTick).toHaveBeenCalled();
   expect(v.errors.count()).toBe(0);
+});
+
+test('resets errors on the next tick if available, complete test asynchronously', (done) => {
+  // not available.
+  let v = new Validator();
+  const vm = { $nextTick: jest.fn(cb => cb()) };
+  v.attach(new Field(null, {}));
+  v.errors.add('some', 'message', 'by');
+  v.reset();
+  expect(v.errors.count()).toBe(0);
+
+  v = new Validator(null, { vm });
+  v.attach(new Field(null, {}));
+  v.errors.add('some', 'message', 'by');
+  v.reset().then(() => {
+    expect(vm.$nextTick).toHaveBeenCalled();
+    expect(v.errors.count()).toBe(0);
+    done();
+  });
 })
 
 test('it can handle mixed successes and errors from one field regardless of rules order', async () => {
Repository: chaijs/chai
Pull request #653 (2016-03-31 11:22:38)

deepStrictEqual
Added `deepStrictEqual` as an alias for `deepEqual`


Patch:
diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js
index 5b44b5c..8160595 100644
--- a/lib/chai/interface/assert.js
+++ b/lib/chai/interface/assert.js
@@ -208,11 +208,12 @@ module.exports = function (chai, util) {
    * @param {Mixed} actual
    * @param {Mixed} expected
    * @param {String} message
+   * @alias deepStrictEqual
    * @namespace Assert
    * @api public
    */
 
-  assert.deepEqual = function (act, exp, msg) {
+  assert.deepEqual = assert.deepStrictEqual = function (act, exp, msg) {
     new Assertion(act, msg).to.eql(exp);
   };
 


Test patch:
diff --git a/test/assert.js b/test/assert.js
index fcfc4d5..ab2f9fd 100644
--- a/test/assert.js
+++ b/test/assert.js
@@ -205,6 +205,7 @@ describe('assert', function () {
 
   it('deepEqual', function() {
     assert.deepEqual({tea: 'chai'}, {tea: 'chai'});
+    assert.deepStrictEqual({tea: 'chai'}, {tea: 'chai'});  // Alias of deepEqual
 
     err(function () {
       assert.deepEqual({tea: 'chai'}, {tea: 'black'});
Repository: chaijs/chai
Pull request #680 (2016-04-17 12:56:02)

Fix failure when custom inspect method is used
When custom inspect method is used and this method calls stylize test crashes.
Stylize method is documented for Node.js 4.x and 5.x.

Objects which use custom `inspect` method for `util.inspect` in Node.js should not cause test errors.


Patch:
diff --git a/lib/chai/utils/inspect.js b/lib/chai/utils/inspect.js
index 7373481..71297ee 100644
--- a/lib/chai/utils/inspect.js
+++ b/lib/chai/utils/inspect.js
@@ -49,7 +49,7 @@ function formatValue(ctx, value, recurseTimes) {
       value.inspect !== exports.inspect &&
       // Also filter out any prototype objects using the circular check.
       !(value.constructor && value.constructor.prototype === value)) {
-    var ret = value.inspect(recurseTimes);
+    var ret = value.inspect(recurseTimes, ctx);
     if (typeof ret !== 'string') {
       ret = formatValue(ctx, ret, recurseTimes);
     }


Test patch:
diff --git a/test/utilities.js b/test/utilities.js
index 8270a7c..100ae88 100644
--- a/test/utilities.js
+++ b/test/utilities.js
@@ -608,6 +608,19 @@ describe('utilities', function () {
     });
   });
 
+  it('inspect with custom stylize-calling inspect()s', function () {
+    chai.use(function (_chai, _) {
+      var obj = {
+        outer: {
+          inspect: function (depth, options) {
+            return options.stylize('Object content', 'string');
+          }
+        }
+      };
+      expect(_.inspect(obj)).to.equal('{ outer: Object content }');
+    });
+  });
+
   it('inspect with custom object-returning inspect()s', function () {
     chai.use(function (_chai, _) {
       var obj = {
Repository: chaijs/chai
Pull request #689 (2016-04-25 01:30:53)

Fix ownProperty on objects with no prototype
Solves #688 

Objects with no prototype can now be succesfully tested for containing properties.


Patch:
diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js
index 37e0ced..9ca0b0c 100644
--- a/lib/chai/core/assertions.js
+++ b/lib/chai/core/assertions.js
@@ -937,7 +937,7 @@ module.exports = function (chai, _) {
     if (msg) flag(this, 'message', msg);
     var obj = flag(this, 'object');
     this.assert(
-        obj.hasOwnProperty(name)
+        Object.prototype.hasOwnProperty.call(obj, name)
       , 'expected #{this} to have own property ' + _.inspect(name)
       , 'expected #{this} to not have own property ' + _.inspect(name)
     );


Test patch:
diff --git a/test/expect.js b/test/expect.js
index f12fe54..04e79c4 100644
--- a/test/expect.js
+++ b/test/expect.js
@@ -565,6 +565,10 @@ describe('expect', function () {
     expect('test').to.haveOwnProperty('length');
     expect({ length: 12 }).to.have.ownProperty('length');
 
+    var objNoProto = Object.create(null);
+    objNoProto.a = 'a';
+    expect(objNoProto).to.have.ownProperty('a');
+
     err(function(){
       expect({ length: 12 }).to.not.have.ownProperty('length', 'blah');
     }, "blah: expected { length: 12 } to not have own property 'length'");
diff --git a/test/should.js b/test/should.js
index 876f934..7fdf495 100644
--- a/test/should.js
+++ b/test/should.js
@@ -417,6 +417,10 @@ describe('should', function() {
     ({ length: 12 }).should.have.ownProperty('length');
     ({ 1: 1 }).should.have.ownProperty(1);
 
+    var objNoHasOwnProperty = {hasOwnProperty: null};
+    objNoHasOwnProperty.a = 'a';
+    objNoHasOwnProperty.should.have.ownProperty('a');
+
     err(function(){
       ({ length: 12 }).should.not.have.ownProperty('length', 'blah');
     }, "blah: expected { length: 12 } to not have own property 'length'");
Repository: chaijs/chai
Pull request #801 (2016-09-15 02:52:25)

Add toJSON to proxyExcludedKeys
Hello there,

While I was working on #799, I discovered that you cannot call `JSON.stringify` on an assertion because o proxify.

```javascript
const { expect } = require('chai');

const equal1 = expect(1).to.equal(1);

JSON.stringify(equal); // Error: Invalid Chai property: toJSON
```


Patch:
diff --git a/lib/chai/config.js b/lib/chai/config.js
index 9c8be3c..ca1e30a 100644
--- a/lib/chai/config.js
+++ b/lib/chai/config.js
@@ -90,5 +90,5 @@ module.exports = {
    * @api public
    */
 
-  proxyExcludedKeys: ['then', 'inspect']
+  proxyExcludedKeys: ['then', 'inspect', 'toJSON']
 };


Test patch:
diff --git a/test/configuration.js b/test/configuration.js
index 5eef76c..d0399c4 100644
--- a/test/configuration.js
+++ b/test/configuration.js
@@ -206,8 +206,8 @@ describe('configuration', function () {
       }
     };
 
-    it('should have default value equal to `[\'then\', \'inspect\']`', function() {
-      expect(chai.config.proxyExcludedKeys).to.be.deep.equal(['then', 'inspect']);
+    it('should have default value equal to `[\'then\', \'inspect\', \'toJSON\']`', function() {
+      expect(chai.config.proxyExcludedKeys).to.be.deep.equal(['then', 'inspect', 'toJSON']);
     });
 
     it('should not throw when accessing non-existing `then` and `inspect` in an environment with proxy support', function() {
Repository: chaijs/chai
Pull request #802 (2016-09-15 18:09:56)

Fix bug when trying to call inspect on an Assertion
Hello everyone!
As me and @vieiralucas were taking a look at Chai's code yesterday on college, we noticed that there was a bug when an assertion which had other `Assertion` objects as `expected` or `actual` failed.

This was happening because mocha called the `.inspect` method on them and it tried to read the property `nodeType`, which did not exist on the `Assertion` object and ended up throwing an error.

To fix this I simply added a check before accessing that property, calling `hasOwnProperty` and passing the `object` we're inspecting (as `this`) and `'nodeType'`.

vieiralucas: LGTM

Patch:
diff --git a/lib/chai/utils/inspect.js b/lib/chai/utils/inspect.js
index ef3590c..a53a336 100644
--- a/lib/chai/utils/inspect.js
+++ b/lib/chai/utils/inspect.js
@@ -37,6 +37,7 @@ var isDOMElement = function (object) {
   } else {
     return object &&
       typeof object === 'object' &&
+      'nodeType' in object &&
       object.nodeType === 1 &&
       typeof object.nodeName === 'string';
   }


Test patch:
diff --git a/test/utilities.js b/test/utilities.js
index 512a759..0524d0b 100644
--- a/test/utilities.js
+++ b/test/utilities.js
@@ -819,6 +819,17 @@ describe('utilities', function () {
     });
   });
 
+  it('inspect an assertion', function () {
+    chai.use(function (_chai, _) {
+      var assertion = expect(1);
+      var anInspectFn = function() {
+        return _.inspect(assertion);
+      };
+
+      expect(anInspectFn).to.not.throw();
+    });
+  });
+
   it('truncate long TypedArray', function () {
     chai.use(function (_chai, _) {
Repository: chaijs/chai
Pull request #992 (2017-06-10 22:07:37)

fix: check target's type in `.property` assertion
Previously, the `.property` assertion failed ungracefully if the target was `null` or `undefined`. This commit causes an `AssertionError` to be thrown instead so that the ssfi flag and custom error messages are respected.


Patch:
diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js
index d6c0be6..0e15722 100644
--- a/lib/chai/core/assertions.js
+++ b/lib/chai/core/assertions.js
@@ -1644,6 +1644,7 @@ module.exports = function (chai, _) {
     var isNested = flag(this, 'nested')
       , isOwn = flag(this, 'own')
       , flagMsg = flag(this, 'message')
+      , obj = flag(this, 'object')
       , ssfi = flag(this, 'ssfi');
 
     if (isNested && isOwn) {
@@ -1655,9 +1656,17 @@ module.exports = function (chai, _) {
       );
     }
 
+    if (obj === null || obj === undefined) {
+      flagMsg = flagMsg ? flagMsg + ': ' : '';
+      throw new AssertionError(
+        flagMsg + 'Target cannot be null or undefined.',
+        undefined,
+        ssfi
+      );
+    }
+
     var isDeep = flag(this, 'deep')
       , negate = flag(this, 'negate')
-      , obj = flag(this, 'object')
       , pathInfo = isNested ? _.getPathInfo(obj, name) : null
       , value = isNested ? pathInfo.value : obj[name];
 


Test patch:
diff --git a/test/assert.js b/test/assert.js
index 9cfff71..9a36f59 100644
--- a/test/assert.js
+++ b/test/assert.js
@@ -1339,6 +1339,14 @@ describe('assert', function () {
     err(function () {
       assert.notNestedPropertyVal(obj, 'foo.bar', 'baz', 'blah');
     }, "blah: expected { foo: { bar: 'baz' } } to not have nested property 'foo.bar' of 'baz'");
+
+    err(function () {
+      assert.property(null, 'a', 'blah');
+    }, "blah: Target cannot be null or undefined.");
+
+    err(function () {
+      assert.property(undefined, 'a', 'blah');
+    }, "blah: Target cannot be null or undefined.");
   });
 
   it('deepPropertyVal', function () {
diff --git a/test/expect.js b/test/expect.js
index 2194110..6f3f45d 100644
--- a/test/expect.js
+++ b/test/expect.js
@@ -1263,6 +1263,14 @@ describe('expect', function () {
     err(function() {
       expect({a: {b: 1}}, 'blah').to.have.own.nested.property("a.b");
     }, "blah: The \"nested\" and \"own\" flags cannot be combined.");
+
+    err(function () {
+      expect(null, 'blah').to.have.property("a");
+    }, "blah: Target cannot be null or undefined.");
+
+    err(function () {
+      expect(undefined, 'blah').to.have.property("a");
+    }, "blah: Target cannot be null or undefined.");
   });
 
   it('property(name, val)', function(){
Repository: chaijs/chai
Pull request #1349 (2020-06-17 14:36:25)

unbox BigInt primitives in shouldGetter
Partially addresses https://github.com/chaijs/chai/issues/1321 so that global `should` getter unboxes primitive BigInt values.

Lemme know if I should write any tests.

keithamus: Thanks for doing this @dwelle :+1:

Please could you write a couple of tests just so we don't end up regressing this behaviour? Thanks!
dwelle: I've written tests for the unboxing behavior, and when I was at it wrote for other types as well. Hopefully I didn't duplicate it from somewhere else. Used a custom assertion -- not sure if I should have use chai assertions for this.

Patch:
diff --git a/lib/chai/interface/should.js b/lib/chai/interface/should.js
index 5406e5e..17902af 100644
--- a/lib/chai/interface/should.js
+++ b/lib/chai/interface/should.js
@@ -13,7 +13,8 @@ module.exports = function (chai, util) {
       if (this instanceof String
           || this instanceof Number
           || this instanceof Boolean
-          || typeof Symbol === 'function' && this instanceof Symbol) {
+          || typeof Symbol === 'function' && this instanceof Symbol
+          || typeof BigInt === 'function' && this instanceof BigInt) {
         return new Assertion(this.valueOf(), null, shouldGetter);
       }
       return new Assertion(this, null, shouldGetter);


Test patch:
diff --git a/test/should.js b/test/should.js
index 8a44913..4e97f42 100644
--- a/test/should.js
+++ b/test/should.js
@@ -397,6 +397,27 @@ describe('should', function() {
     }, "expected [] to be arguments but got Array");
   });
 
+  it('".should" getter should unbox primitive values', function(){
+    function assert(value) {
+      const AssertionObject = value.should;
+      const type = typeof value;
+      if (AssertionObject.__flags.object !== value) {
+        throw new Error("value `"+ value.toString() +"` ("+ type +") wasn't unboxed");
+      }
+    };
+
+    assert("a");
+    assert(0);
+    assert(true);
+    assert(false);
+    if (typeof Symbol === 'function') {
+      assert(Symbol("a"));
+    }
+    if (typeof BigInt === 'function') {
+      assert(BigInt(10));
+    }
+  });
+
   it('.equal()', function(){
     var foo;
     should.equal(undefined, foo);
Repository: chaijs/chai
Pull request #1383 (2021-03-12 15:58:05)

fix: support inspecting bigints (#1321)
Replaces #1365.


Patch:
diff --git a/chai.js b/chai.js
index 9faa3e5..e1520f7 100644
--- a/chai.js
+++ b/chai.js
@@ -8746,6 +8746,9 @@ function formatPrimitive(ctx, value) {
 
     case 'symbol':
       return ctx.stylize(value.toString(), 'symbol');
+
+    case 'bigint':
+      return ctx.stylize(value.toString() + 'n', 'bigint');
   }
   // For some reason typeof null is "object", so special case here.
   if (value === null) {
diff --git a/lib/chai/utils/inspect.js b/lib/chai/utils/inspect.js
index b054aeb..fbb9997 100644
--- a/lib/chai/utils/inspect.js
+++ b/lib/chai/utils/inspect.js
@@ -218,6 +218,9 @@ function formatPrimitive(ctx, value) {
 
     case 'symbol':
       return ctx.stylize(value.toString(), 'symbol');
+
+    case 'bigint':
+      return ctx.stylize(value.toString() + 'n', 'bigint');
   }
   // For some reason typeof null is "object", so special case here.
   if (value === null) {


Test patch:
diff --git a/test/utilities.js b/test/utilities.js
index a5f3c8f..0d5b2cf 100644
--- a/test/utilities.js
+++ b/test/utilities.js
@@ -756,6 +756,16 @@ describe('utilities', function () {
     });
   });
 
+  it('inspect BigInt', function () {
+    if (typeof BigInt !== 'function') return;
+
+    chai.use(function (_chai, _) {
+      expect(_.inspect(BigInt(0))).to.equal('0n');
+      expect(_.inspect(BigInt(1234))).to.equal('1234n');
+      expect(_.inspect(BigInt(-1234))).to.equal('-1234n');
+    });
+  });
+
   it('inspect every kind of available TypedArray', function () {
     chai.use(function (_chai, _) {
       var arr = [1, 2, 3]