Skip to content

Strings & Collections

String matchers

These operate on string values. Matching is plain substring matching — not regular expressions.

ts
expect("assemblyscript").toMatch("script");   // contains
expect("as-test").toStartWith("as");          // prefix
expect("report.tap").toEndWith(".tap");        // suffix
MatcherPasses when
toMatch(sub)the string contains sub
toStartWith(prefix)the string starts with prefix
toEndWith(suffix)the string ends with suffix

Length

toHaveLength works on strings and arrays:

ts
expect("hello").toHaveLength(5);
expect([1, 2, 3]).toHaveLength(3);

Containment

toContain (and its alias toContains) checks membership. For arrays it uses .includes(); for strings it checks for a substring:

ts
expect([1, 2, 3]).toContain(2);
expect("assemblyscript").toContain("script");
MatcherOn arraysOn strings
toContain(value)element is presentsubstring is present
toContains(value)alias for toContainalias for toContain
toHaveLength(n)array.length == nstring.length == n

Negate any of them with .not:

ts
expect(tags).not.toContain("deprecated");
expect(name).not.toHaveLength(0);