Setting same properties name causing tests fail
See original GitHub issueHello everyone!
After digging into an annoying problem I discovered what is causing the bugs in valid tests… I think after we use a property name this name is invalid to be used again…
This is the helper code:
import { helper } from '@ember/component/helper';
export default helper(function truncateText([ value ], { limit }) {
let text = '';
if (value != null && value.length > 0) {
text = value.substr(0, limit);
if (value.length > limit) {
text += '...';
}
}
return text;
});
This is my helper test:
import { expect } from 'chai';
import { describe, it, beforeEach } from 'mocha';
import { setupRenderingTest } from 'ember-mocha';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
describe('TruncateTextHelper', async function() {
setupRenderingTest();
beforeEach(function() {
this.set('text', 'my awesome but very large text!!');
});
it('does truncate text when is greater than limit', async function() {
await render(hbs`{{truncate-text this.text limit=10}}`);
expect(this.element.textContent).to.be.include('my awesome...');
});
it('does not truncate text when lower than limit', async function() {
await render(hbs`{{truncate-text this.text limit=100}}`);
expect(this.element.textContent).to.be.include('my awesome but very large text!!');
});
});
If I remove the beforeEach
, and pass the same property directly the problem still happens
describe('TruncateTextHelper', async function() {
setupRenderingTest();
it('does truncate text when is greater than limit', async function() {
this.set('text', 'my awesome but very large text!!');
await render(hbs`{{truncate-text this.text limit=10}}`);
expect(this.element.textContent).to.be.include('my awesome...');
});
it('does not truncate text when lower than limit', async function() {
this.set('text', 'my awesome but very large text!!');
await render(hbs`{{truncate-text this.text limit=100}}`);
expect(this.element.textContent).to.be.include('my awesome but very large text!!');
});
});
This is the error:
Logging the properties, we got the "my awesome but very large text!!"
for the first occurrence and undefined
for the second.
If I change the name of the last property from text
to something
it works!
I’ve provided a little package with the failing specs: https://github.com/brunoocasali/bookish-octo-garbanzo/blob/master/tests/integration/helpers/truncate-text-test.js
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Value config injection failing - spring - Stack Overflow
You need to add a PropertySourcesPlaceholderConfigurer or PropertyPlaceholderConfigurer to your test context. This SO question may give you ...
Read more >Test context reading 'wrong' application properties file #534
Due to that all the test fail as are not finding the expected ... and "spring.config.name": "application.properties" but with no success ...
Read more >Best practices for writing unit tests - .NET - Microsoft Learn
When you have a suite of well-named unit tests, each test should be ... Setting extra properties on models or using non-zero values...
Read more >Maven Surefire Plugin – surefire:test - Apache Maven
User property is: maven.test.dependency.excludes . ... <failIfNoTests>, boolean, 2.4, Set this to "true" to cause a failure if there are no ...
Read more >Java Unit Testing with JUnit and TestNG
xUnit is the family name given to a group of unit testing frameworks that share the ... Each test method runs on its...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be fixed now thanks to @kobsy?
I’ve found out that setting the property without
set
works, like this: