facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Running test not passing #276

Closed lpeliberty closed 5 years ago

lpeliberty commented 5 years ago

Hello, I forked your project because I'm implementing something with immutable. Once I've done my things, if I run test, it does not pass because :

● PropTypesProductionReact15 › React Component Types › should not warn for iterables

TypeError: Assignment to constant variable.

  at Object.next (__tests__/PropTypesProductionReact15-test.js:511:30)

and

● PropTypesProductionReact15 › React Component Types › should not warn for entry iterables

TypeError: Assignment to constant variable.

  at Object.next (__tests__/PropTypesProductionReact15-test.js:531:30)

As I can see, this is the code that fail :

const iterable = {
        '@@iterator': function() {
          const i = 0;
          return {
            next: function() {
              const done = ++i > 2;
              return {value: done ? undefined : <MyComponent />, done: done};
            },
          };
        },
      };

++i does increment the i const.

So, if i change by :

const iterable = {
        '@@iterator': function() {
          let i = 0;
          return {
            next: function() {
              const done = ++i > 2;
              return {value: done ? undefined : <MyComponent />, done: done};
            },
          };
        },
      };

It's ok.

The fact is if I run test without changes, everythings pass, but id I add my function (creating an immutable type checker in factoryWithTypeCheckers.js), these tests fails.

What do you think about it ? Thx all !!

ljharb commented 5 years ago

I don’t see that code in this repo. Can you link to your added code?

lpeliberty commented 5 years ago

I can't link to my repo because it's a private repo, sorry.

But I can link the lines where it fails : First fail Second fail

When I run yarn test, I have these 2 fails.

ljharb commented 5 years ago

the test descriptions say it should be a noop in production - perhaps your new code is incorrectly running in production, otherwise that iterator next wouldn’t be invoked?

lpeliberty commented 5 years ago

OK, so I should check why this function is iterated, next should'nt be invoked ! Thx