Repository: facebook/react
File: src/utils/__tests__/ImmutableObject-test.js (JavaScript)

Code before:
    expect(window.__DEV__).toBe(true);
  });

  testDev('should require initial map to be an object', function() {
    expect(function() {
      new ImmutableObject([1,2,3]);
    }).toThrow();

    expect(function() {
      new ImmutableObject('asdf');
    }).toThrow();

    expect(function() {
      new ImmutableObject({oldField: 'asdf', fieldTwo: null});
    }).not.toThrow();
  });

  testDevAndProd('should not throw when not mutating directly', function() {
    var io = new ImmutableObject({oldField: 'asdf'});
    expect(function() {
      ImmutableObject.set(io, {newField: null}); // not a mutation!
    }).not.toThrow();
  });

  testDev('should prevent shallow field addition when strict', function() {
    expect(function() {
      var io = new ImmutableObject({oldField: 'asdf'});
      io.newField = 'this will not work';
    }).toThrow();
  });

  testDev('should prevent shallow field mutation when strict', function() {
    expect(function() {
      var io = new ImmutableObject({oldField: 'asdf'});
      io.oldField = 'this will not work!';
    }).toThrow();
  });

  testDev('should prevent deep field addition when strict', function() {
    expect(function() {
      var io =
        new ImmutableObject({shallowField: {deepField: {oldField: null}}});
      io.shallowField.deepField.oldField = 'this will not work!';
    }).toThrow();
  });

  testDev('should prevent deep field mutation when strict', function() {
    expect(function() {
      var io =
        new ImmutableObject({shallowField: {deepField: {oldField: null}}});
      io.shallowField.deepField.newField = 'this will not work!';

Review comment (bug):
The tests will pass, but there will be fewer `expect`-ations counted in the final tally.

These tests can still be run in the browser if you do `grunt test --debug`.


Code after:
    expect(window.__DEV__).toBe(true);
  });

  testDev('should require initial map to be an object', function() {
    expect(function() {
      new ImmutableObject([1,2,3]);
    }).toThrow();

    expect(function() {
      new ImmutableObject('asdf');
    }).toThrow();

    expect(function() {
      new ImmutableObject({oldField: 'asdf', fieldTwo: null});
    }).not.toThrow();
  });

  testDevAndProd('should not throw when not mutating directly', function() {
    var io = new ImmutableObject({oldField: 'asdf'});
    expect(function() {
      ImmutableObject.set(io, {newField: null}); // not a mutation!
    }).not.toThrow();
  });

  testDev('should prevent shallow field addition when strict', function() {
    if (window.callPhantom) return;
    expect(function() {
      var io = new ImmutableObject({oldField: 'asdf'});
      io.newField = 'this will not work';
    }).toThrow();
  });

  testDev('should prevent shallow field mutation when strict', function() {
    if (window.callPhantom) return;
    expect(function() {
      var io = new ImmutableObject({oldField: 'asdf'});
      io.oldField = 'this will not work!';
    }).toThrow();
  });

  testDev('should prevent deep field addition when strict', function() {
    if (window.callPhantom) return;
    expect(function() {
      var io =
        new ImmutableObject({shallowField: {deepField: {oldField: null}}});
      io.shallowField.deepField.oldField = 'this will not work!';
    }).toThrow();
  });

  testDev('should prevent deep field mutation when strict', function() {
    if (window.callPhantom) return;