question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting same properties name causing tests fail

See original GitHub issue

Hello 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: image

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:open
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
lolmauscommented, May 12, 2020

Should be fixed now thanks to @kobsy?

1reaction
HenryVonfirecommented, Oct 11, 2019

I’ve found out that setting the property without set works, like this:

  beforeEach(function() {
    this.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!!');
  });
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found