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.

Check assertion message is a string

See original GitHub issue

(See https://github.com/avajs/ava/issues/1125#issuecomment-264707430, @novemberborn)


node@6.8, ava@0.17.0

When I run test, sometimes I get this error:

TypeError: test.error.message.split is not a function
    at /Users/creeper/work/projects/ysprite/node_modules/ava/lib/reporters/mini.js:181:43
    at Array.forEach (native)
    at MiniReporter.finish (/Users/creeper/work/projects/ysprite/node_modules/ava/lib/reporters/mini.js:173:20)
    at Logger.finish (/Users/creeper/work/projects/ysprite/node_modules/ava/lib/logger.js:49:27)
    at /Users/creeper/work/projects/ysprite/node_modules/ava/lib/cli.js:161:12
From previous event:
    at Object.exports.run (/Users/creeper/work/projects/ysprite/node_modules/ava/lib/cli.js:160:5)
    at Object.<anonymous> (/Users/creeper/work/projects/ysprite/node_modules/ava/cli.js:23:24)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

And I found this maybe caused by:

test('message', t => {
  return aPromise.then(() => {
    // error occured 
  })
})

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
leewaygroupscommented, Jan 7, 2017

May I take on this as a gentle step into AVA.

One question: For uniformity, would it not make sense to apply same check in other sibling functions such truthy, falsy etc?

In that case the check can be centralised as a helper and invoked in all sibling functions where it is needed.

0reactions
novemberborncommented, Jun 28, 2018

To clarify, per https://github.com/avajs/ava/pull/1831#issuecomment-396913731, we want to type check the message parameter when the assertion is invoked, and fail the assertion if the parameter is not undefined and not a string.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assertion fail message for string contains substring [duplicate]
String failMsg = String.format("Wanted string to contain: %s, Actual string: %s", wantedString, actualString); assertTrue(failMsg, actualString.
Read more >
Check If a String Contains a Substring - Baeldung
In this tutorial, we'll review several ways of checking if a String contains a substring, and we'll compare the performance of each.
Read more >
How to print a message after checking through TestNG's ...
The easiest way is to wrap the assertion within a try-catch block, something like: try { Assert.assertEquals(actualString, expectedString); } catch ...
Read more >
Junit Assert & AssertEquals with Example - Guru99
Assert is a method useful in determining Pass or Fail status of a test case, The assert methods are provided by the class...
Read more >
assert-on-string-literal / W0129 - Pylint
Directly asserting a string literal will always pass. The solution is to test something that could fail, or not assert at all. For...
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