Angular2测试和RESOURCE_CACHE_PROVIDER全局

时间:2017-06-14 08:31:55

标签: angular karma-jasmine

我正在寻找一种方法,在[{1}}

上的initTest阶段将提供商var myVar = <?php echo $yourPhpVariable; ?>; 设置为RESOURCE_CACHE_PROVIDER

我们无法修改单个测试,因为我们也会在ResourceLoader上用karma-test-shim.src.js替换templateUrl的dist文件夹中使用它们

在这里,我们已经进行了一些测试但没有成功:

template

1 个答案:

答案 0 :(得分:1)

我们找到了一个解决方案,但不是基于Angular提供商。

我们开发了一个简单的业力预处理器,仅用于测试:

gulp-inline-ng2-template

然后预处理器只使用genericPreprocessor: { rules: [{ process: function (content, file, done, log) { // Prepare content for parser file.contents = new Buffer(content); // Every file has a parser var parse = require('gulp-inline-ng2-template/parser')(file, { base: "packages/", useRelativePaths: false }); // Call real parse function parse(function (err, contents) { // Callback with content with template and style inline done(contents); }); } }] }, 解析器

class Worker {

    public function put($ip, $user, $file)
    {
        try {
            $response = $this->client->post('/put', ['form_params' => ['ip' => $ip,'username' => $user, 'file'  => $file]]);

            $responseBody = (string)$response->getBody();
            // do something

        } catch (ClientException | ServerException $e) {
            return $this->handleRequestError($e);
        }
    }


    protected function handleRequestError($e)
    {
        if ($e instanceof ClientException) {
            if ($e->getCode() == 422) {
                throw new WorkerValidationException((string)$e->getResponse()->getBody());
            }
        }

        if ($e instanceof ServerException) {
            $error = json_decode($e->getResponse()->getBody(), true);

            if ($error['error_type'] == 'ftp') {
                throw new FtpException((string)$e->getResponse()->getBody());
            }

            if ($error['error_type'] == 'somethingElse') {
                throw new SomethingElseException((string)$e->getResponse()->getBody());
            }
        }


        throw new \Exception((string) $e->getResponse()->getBody());
    }
}