这是我用打字稿写的角度工厂:
export class DataService {
constructor () {
this.setYear(2015);
}
setYear = (year:number) => {
this._selectedYear =year;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试文件.
import {DataService } from ' ./sharedData.Service';
export function main() {
describe("DataService", () => {
let service: DataService;
beforeEach(function () {
service = new DataService();
});
it("should initialize shared data service", () => {
spyOn(service, "setYear");
expect(service).toBeDefined();
expect(service.setYear).toHaveBeenCalled(2015);
});
});
}
Run Code Online (Sandbox Code Playgroud)
当我运行该文件时,测试失败了
**Expected spy setSelectedCropYear to have been called.
Error: Expected spy setSelectedCropYear to have been called.**
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚出了什么问题.任何人都可以告诉我测试有什么问题.
这是我的控制器:
export class testController {
static $inject: string[] = ["testService", "$mdDialog", "$state"];
constructor(public _testService: services.testService, private _mdDialog: any, private _$state: any) {
this.isCurrentlyEditing = false;
this.activate();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的单元测试:
import {test as service} from './test.service';
import {test as ctrl} from './test.controller';
export function main() {
describe("testController", () => {
var mdDialog: angular.material.IDialogService;
var state: ng.ui.IStateService;
var testService: any;
var controller: any;
beforeEach(function () {
angular.mock.module('comp.modules.addField');
});
beforeEach(function () {
testService = {
showCLULayer: () => { } …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 window 对象上附加属性。这是我的代码。
cbid:string ='someValue';
window[cbid] = (meta: any) => {
tempThis.meta = meta;
window[cbid] = undefined;
var e = document.getElementById(cbid);
e.parentNode.removeChild(e);
if (meta.errorDetails) {
return;
}
};
Run Code Online (Sandbox Code Playgroud)
编译器开始抛出以下错误。
对象类型的 TypeScript 索引签名隐式具有类型 any
有人可以告诉我我在哪里做错了吗?
这是我的角度视图
<li class= "riskmanagementlink" ng-repeat="link in links">
<h3> {{link.Description}} </h3>
<a> {{link.Title}} </a>
<hr/>
</li>
Run Code Online (Sandbox Code Playgroud)
我想删除最后一个列表项的hr标记.有人可以帮我这么做吗?
这是我要测试的控制器功能.
saveItem = (): void => {
this.updateItem();
this.loadingDialogService.showIndicator("Saving Item");
this._editItemService.updateItem(this.item).then((updatedItem: Item) => {
this.loadingDialogService.cancelDialog();
this.goToMainView();
}).catch(() => {
this.loadingDialogService.showErrorDialog("Failed to Save Item");
//this._log.error("Error CallingItemService");
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试:
it("should call method saveItem", () => {
spyOn(controller, 'updateItem');
spyOn(loadingDialogService, 'showIndicator');
spyOn(editItemService, 'updateItem').and.callFake(() => {
let result: Item
deferred.resolve(result);
return deferred.promise;
});
spyOn(loadingDialogService, 'cancelDialog');
spyOn(controller, 'goToMainView');
controller.saveItem();
expect(controller.updateItem).toHaveBeenCalled();
expect(loadingDialogService.showIndicator).toHaveBeenCalled();
expect(_editItemService.updateItem).toHaveBeenCalled();
expect(loadingDialogService.cancelDialog).toHaveBeenCalled();
expect(controller.goToMainView).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
测试在最后两次预期失败,抛出错误说
预计间谍cancelDialog已被调用.
已被调用的间谍goToMainView被调用.
我想测试不执行内部功能则功能.有人可以指出错误在哪里吗?
这是我的观点:
class SampleViewSet(viewsets.ModelViewSet):
serializer_class = SampleSerializer
queryset = Sample.objects.all()
def get_queryset(self):
queryset = self.queryset
test_code = self.request.query_params.get('test_code', None)
if test_code is not None:
queryset = queryset.filter(test__test_code=test_code)
return queryset
Run Code Online (Sandbox Code Playgroud)
这是我的模型:
class Sampe(models.Model):
test = models.OneToOneField(Test, null=True, blank=True, on_delete=models.CASCADE)
# few more fields- not so important
Run Code Online (Sandbox Code Playgroud)
这是我的序列化程序:
class SampleSerializer(serializers.ModelSerializer):
test_code = serializers.CharField(source='test.test_code')
class Meta:
model = Sample
fields = '__all__'
Run Code Online (Sandbox Code Playgroud)
这在我点击 /api/sample?test_code="existing_param" 时有效所以当我做 /api/sample?test_code="Not_Existing_param" 时,我期望它应该抛出 404 代替,它抛出 500 测试匹配查询不存在。真的很感激任何帮助。
谢谢
我有一个网站(静态坐在s3),内容从s3提供.我打算写一个休息api(节点或对建议开放).当前端进行角度$ http调用时,例如,如果我的网站名为example.com,那么调用将是类似相对url(/ Update)的解决方案.
我不确定,我应该使用什么类型的aws服务来部署我的后端代码.
更新
我正在使用Codestar,使用Express Web服务.这是我的template.yml.和路线.代码星构建很好,但部署失败.
template.yml
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
- AWS::CodeStar
Parameters:
ProjectId:
Type: String
Description: AWS CodeStar projectID used to associate new resources to team members
Resources:
HelloWorld:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
Role:
Fn::ImportValue:
!Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
Events:
GetEvent:
Type: Api
Properties:
Path: /
Method: get
PostEvent:
Type: Api
Properties:
Path: /
Method: post
GetItemsBylId:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
Role:
Fn::ImportValue:
!Join ['-', [!Ref 'ProjectId', …
Run Code Online (Sandbox Code Playgroud) amazon-s3 amazon-ec2 amazon-web-services angularjs aws-lambda
我有收集对象
public ICollection<DataOutput> DataCollection { get; set; }
Run Code Online (Sandbox Code Playgroud)
当我尝试循环收集
for(DataOutput item in data.DataCollection)
{
}
Run Code Online (Sandbox Code Playgroud)
它说只有赋值调用增量减量可以用作下面的语句data.DataCollection
.任何人都可以指出我在做错误的地方吗?
angularjs ×5
jasmine ×3
typescript ×2
.net ×1
amazon-ec2 ×1
amazon-s3 ×1
aws-lambda ×1
c# ×1
django ×1
django-views ×1
html ×1
javascript ×1
jquery ×1