gpt4 book ai didi

javascript - 陷入 karma 报应验证作业(nodejs,angularjs)

转载 作者:行者123 更新时间:2023-12-02 14:51:09 25 4
gpt4 key购买 nike

我的作业是 MEAN Stack其中需要更改 2 个文件才能通过 karma 测试。这两个文件是 search_bar.htmlcontroller.js 中的函数。这个想法是使test.js文件传递。

听起来很简单,但我无法为我一生的挚爱做到这一点。我一遍又一遍地阅读作业,这就是我得到的:

search_bar.html:

<div class="search-bar-wrapper">
<input class="search-bar-input" ng-model="searchText" ng-change="update()"/>
</div>

<div ng-repeat="product in productsList" class="autocomplete-result">
{{product}}
</div>

Controller.js:

exports.SearchBarController = function($scope, $http) {
// TODO: this function should make an HTTP request to
// `/api/v1/product/text/:searchText` and expose the response's
// `products` property as `results` to the scope.
$scope.update = function() {
$http.
get('/api/v1/product/text/' + $scope.searchText).
success(function(data) {
$scope.productsList = data;
}
);
};

作业的目标如下:

  • You will have to modify SearchBarController in controllers.js to fill out the update() function, which will make an HTTP request to the server and expose the server's response to your HTML.

  • You will have to modify the HTML in templates/search_bar.html to add an input field with class 'search-bar-input' that has a two-way data binding to the searchText variable, and calls the update() function using the ngChange directive. You will also need to ngRepeat a div element with class 'autocomplete-result' for each search result.

我相信我当前的代码就是这样做的,但显然这是错误的。我已经被困在这里很长一段时间了,我看不出哪里出了问题。

有人可以帮忙吗?

================================================== ===============

其他信息:

如果您感到好奇或想做今天的善事(我希望上帝您会这样做),这里有关于作业的附加信息,以及 zip file有了它:

In this exercise, you will implement the home view for the MEAN retail application, the first view that the user will see when they visit your site. The view contains a single search bar that searches for products by text, that is, using the/api/v1/product/text/:query REST API endpoint.

You will primarily be concerned with writing code that passes the mocha tests specified in the test.js file. You will notneed to actually run your code in the browser, you will instead use gulp and karma to run your tests. The tests intest.js will provide you faster feedback, and also will provide you an exact specification for what you need to do to complete this exercise.

In order to run tests, you should:

  • Run npm install in the provided sample code
  • Start gulp using ./node_modules/gulp/bin/gulp watch
  • Start karma using ./node_modules/karma/bin/karma start ./karma.local.conf.js
  • You should take a look at the tests in test.js to see exactly what your AngularJS code should do.
  • Modify controllers.js and templates/search_bar.html as described below until the tests pass and karma gives you the below output:

    LOG: 'Tests Succeeded! Copy/paste the below code to complete this assignment:' LOG: '' Chrome 43.0.2357 (Linux): Executed 4 of 4 SUCCESS (0.21 secs / 0.126 secs)

最佳答案

  1. "makes an HTTP request to /api/v1/product/text/test and exposes results to scope"

$scope.productsList = data; 应该是 $scope.results = data; (请务必阅读问题,您的讲师或撰写 TODO 评论的人告诉您您将其命名为 results,而不是 productsList),当然,您引用的其他任何地方 productsList 应更改为 results 也是如此。

  1. "displays autocomplete results in HTML"

{{product}} 应为 {{product.name}}

关于javascript - 陷入 karma 报应验证作业(nodejs,angularjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36182491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com