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

filter function is not executed by test #29

Closed
SamVerschueren opened this issue Mar 22, 2017 · 9 comments
Closed

filter function is not executed by test #29

SamVerschueren opened this issue Mar 22, 2017 · 9 comments

Comments

@SamVerschueren
Copy link

I noticed that the filter is not being executed by the tester. I changed this line to

return Promise.resolve(this.question.filter ? this.question.filter(answer) : answer);

And now everything seems to be working as expected. Not sure if it's that easy to fix though.

@SBoudrias
Copy link
Member

This wouldn't support async filters and it doesn't pass the proper arguments. Given we're mocking inquirer, not running any settings function made sense for us.

@SamVerschueren
Copy link
Author

The default property is taken into account currently though.

The thing is that I was refactoring a filter function and wanted to test if it worked correctly. For instance, Array.prototype.includes only works on Node.js 6 if I'm not mistaken. So if I would test my generator on Node 4 and 6 (LTS), my tests will pass. But if someone installs the generator and runs it, it will crash and 🔥.

In my generator-alfred workflow, I prepend the workflow name with alfred- if it's not already present, I add it in the filter function. So currently, I'm not able to entirely test my workflow.

I just wanted to make sure if this was on purpose or not. I can always take a look to do a PR. But it's your call to make off course :).

@marcofugaro
Copy link

Yeah it was weird when I found this issue, I can't replicate fully the generator behavior in a testing environment

@dankreft
Copy link

Any chance of getting this fixed? I was surprised and disappointed to see that the filter is completely ignored.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2020

This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the stale label Feb 5, 2020
@marcofugaro
Copy link

Only 15 days?? 🤣🤣🤣

@mshima
Copy link
Member

mshima commented Feb 5, 2020

@marcofugaro you just found a bug, please report at https://github.com/yeoman/yeoman-test/issues/new

The relevant part is:

stale-issue-message: 'This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days'
days-before-stale: 45
days-before-close: 15

Just kidding, I am cleaning up irrelevant old issues.

About this issue, I don't now much about inquirer:

This wouldn't support async filters and it doesn't pass the proper arguments. Given we're mocking inquirer, not running any settings function made sense for us.

But added a way to workaround it at #73

@mshima mshima removed the stale label Feb 5, 2020
@mshima
Copy link
Member

mshima commented Feb 16, 2020

Test cases are controlled environment.
In order to test filters, you should use:
withPrompts({ yeoman: 'no please' }, answer => this.question.filter(answer))

@mshima mshima closed this as completed Feb 16, 2020
@niksy
Copy link
Contributor

niksy commented May 6, 2021

What is the proper way of testing filter function? @mshima’s recommendation in last comment doesn’t actually work since it uses arrow function, and converting it to classic function produces another type of error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants