Function

Available since v2.16.4

desc
String
A description of the assertion. This will become the text of the Error thrown if the assertion fails.
test
Boolean
Must be truthy for the assertion to pass. If falsy, an exception will be thrown.

Define an assertion that will throw an exception if the condition is not met.

  • In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build.
1
2
3
4
5
6
7
import { assert } from '@ember/debug';

// Test for truthiness
assert('Must pass a valid object', obj);

// Fail unconditionally
assert('This code path should never be run');