src/Context/TqContext.php
public function checkJavaScriptError($message, $negate, $file)
    {
        $errors = $this->getSession()->evaluateScript('return JSON.stringify(window.errors);');
        $negate = (bool) $negate;

        if (empty($errors)) {
            if (!$negate) {
                throw new \RuntimeException('Page does not contain JavaScript errors.');
            }
        } else {
            $base_url = $this->locatePath();

            foreach (json_decode($errors) as $error) {
                $error->location = str_replace($base_url, '', $error->location);

                switch (static::assertion(
                    strpos($error->message, $message) === 0 && strpos($error->location, $file) === 0,
                    $negate
                )) {
                    case 1:
                        throw new \Exception(sprintf(
                            'The "%s" error found in "%s" file, but should not be.',
                            $message,
                            $file
                        ));

                    case 2:
                        throw new \Exception(sprintf(
                            'The "%s" error not found in "%s" file, but should be.',
                            $message,
                            $file
                        ));
                }
            }
        }
    }
public function checkJavaScriptError($message, $negate, $file)
    {
        $errors = $this->getSession()->evaluateScript('return JSON.stringify(window.errors);');
        $negate = (bool) $negate;

        if (empty($errors)) {
            if (!$negate) {
                throw new \RuntimeException('Page does not contain JavaScript errors.');
            }
        } else {
            $base_url = $this->locatePath();

            foreach (json_decode($errors) as $error) {
                $error->location = str_replace($base_url, '', $error->location);

                switch (static::assertion(
                    strpos($error->message, $message) === 0 && strpos($error->location, $file) === 0,
                    $negate
                )) {
                    case 1:
                        throw new \Exception(sprintf(
                            'The "%s" error found in "%s" file, but should not be.',
                            $message,
                            $file
                        ));

                    case 2:
                        throw new \Exception(sprintf(
                            'The "%s" error not found in "%s" file, but should be.',
                            $message,
                            $file
                        ));
                }
            }
        }
    }
@param string $message
JS error.
@param bool $negate
Whether page should or should not contain the error.
@param string $file
File where error appears.

@throws \RuntimeException
@throws \Exception

@example
Then check that "TypeError: cell[0] is undefined" JS error appears in "misc/tabledrag.js" file

@Then /^check that "([^"]*)" JS error(| not) appears in "([^"]*)" file$/

@javascript