Skip to content

hasText() doesn't work on string like things #1240

Open
@mehulkar

Description

@mehulkar

we often write assertions in ember-land like this:

const i18n = this.owner.lookup('service:i18n')
assert.dom('[data-test-foo']
  .hasText(i18n.t('Some.Key'))

This test fails because i18n.t('Some.Key') is not a string and a TypeError is thrown: https://github.com/simplabs/qunit-dom/blob/e2b3b4f4f82da36733ce659815e092e73ee1c598/lib/assertions.ts#L919-L921

We work around this by changing the assertion to

assert.dom('[data-test-foo']
-  .hasText(i18n.t('Some.Key'))
+  .hasText(String(i18n.t('Some.Key')))

I'm not sure what the right answer, but wanted to report anyway. In our case, we're using ember-i18n, so the return type happens to be a SafeString from Ember's htmlSafe() util.

https://github.com/jamesarosen/ember-i18n/blob/6e4a999d4693e2b85fb99e8c6e34aca4b1670df2/addon/utils/i18n/compile-template.js#L24

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions