我正在使用Ionic框架进行自定义应用程序.在这个过程中,我正在尝试为datastoreServices依赖于DomainService和的工厂编写单元测试$http.我对Jasmine Unit测试的实现感到困惑.
我的工厂如下.
app.factory("datastoreServices", ["$http", function($http) {
    return {
        getData: function(data, DomainService) {
            return $http.post(DomainService.host + 'factor', data);
        }
    };
}]);
app.factory('DomainService', function() { //here
    if (ionic.Platform.isAndroid()) {
        return {
            host: 'http://10.0.2.2:7001/'
        }
    }
    return {
        host: 'http://localhost:7001/'
    }
})
Run Code Online (Sandbox Code Playgroud)
我的单元测试骨架如下.它有两个依赖关系,因此无法弄清楚如何继续.这是我到目前为止在单元测试文件中得到的.
describe(
        'datastoreServices',
        function() {
            beforeEach(module('Myapp'));
            describe('getData'),
                function() {
                    it("Should return correct values", inject(function(datastoreServices, DomainService, $httpBackend) {
                            expect(datastoreServices.getData(httpBackend.. /***something here!**/ )
                                .toEqual("2.2");
                            }))
                    }
Run Code Online (Sandbox Code Playgroud)
我对嘲笑和东西知之甚少.有人可以帮我测试那家工厂吗datastoreServices?以下内容需要测试:
这是plnkr中app的类似场景.
Idk,如果我问得太多了.提前致谢.
我正在将.NET代码转换为Java并遇到精度不匹配的问题.
.NET代码:
private decimal roundToPrecision(decimal number, decimal roundPrecision)
{
    if (roundPrecision == 0)
        return number;
    decimal numberDecimalMultiplier = Math.Round(number / roundPrecision, MidpointRounding.AwayFromZero);
    return numberDecimalMultiplier * roundPrecision;
}
Run Code Online (Sandbox Code Playgroud)
roundToPrecision(8.7250, 0.05);上面代码中的调用函数给出了我8.75期望的函数.
将函数转换/转换为Java如下.我找不到确切的
Math.Round选择.
Java代码:
public double roundToPrecision(double number, double roundPrecision) {
    if (roundPrecision == 0)
        return number;
    int len = Double.toString(roundPrecision).split("\\.")[1].length();
    double divisor = 0d;
    switch (len) {
        case 1:
            divisor = 10d;
            break;
        case 2:
            divisor = 100d;
            break;
        case 3:
            divisor = 1000d;
            break;
        case 4: …Run Code Online (Sandbox Code Playgroud) 我有一个安装了圆形立方体的服务器.我尝试使用我的用户名@ servername从外部电子邮件发送电子邮件.事实证明,我无法阅读电子邮件(收件箱中没有弹出电子邮件),但当我从圆形立方体发送电子邮件到某个外部电子邮件地址时,它工作正常.我想知道是否有任何命令行代码来读取任何用户@server收到的任何电子邮件.
我正在使用 Windows 7X64 机器并尝试使用cordova/ionic CLI v1.5.5. 我收到这个我无法解决的错误。
"You may not have the required environment or OS to build this project"
Run Code Online (Sandbox Code Playgroud)
与命令ionic build android和cordova build android。命令ionic platform add android成功。我正在使用 Android SDK 管理器使用 Android sdk (API 22)。我还确保正确设置了 PATH 变量。
过程的完整记录是:
C:\Users\ddevkota\Desktop\freshIonic>ionic build android
Running command: "C:\Program Files\nodejs\node.exe" C:\Users\ddevkota\Desktop\fr
eshIonic\hooks\after_prepare\010_add_platform_class.js C:\Users\ddevkota\Desktop
\freshIonic
add to body class: platform-android
Running command: cmd "/s /c "C:\Users\ddevkota\Desktop\freshIonic\platforms\andr
oid\cordova\build.bat""
ANDROID_HOME=C:\Users\ddevkota\AppData\Local\Android\sdk
JAVA_HOME=C:\Progra~1\Java\jdk1.7.0_15
Running: C:\Users\ddevkota\Desktop\freshIonic\platforms\android\gradlew cdvBuild
Debug -b C:\Users\ddevkota\Desktop\freshIonic\platforms\android\build.gradle -Do
rg.gradle.daemon=true
Downloading …Run Code Online (Sandbox Code Playgroud) 我有以下 HTTP 拦截器的实现Angular ^4.3.6。
import {Injectable} from "@angular/core";
import {
  HttpInterceptor,
  HttpHandler,
  HttpRequest,
  HttpEvent,
  HttpResponse,
  HttpErrorResponse
} from "@angular/common/http";
import {Observable} from "rxjs/Observable";
import "rxjs/add/operator/do";
@Injectable()
export class InterceptorService implements HttpInterceptor {
  intercept(
    req: HttpRequest<any>,
    next: HttpHandler
): Observable<HttpEvent<any>> {
    return next.handle(req).do(evt => {
      console.log(evt);//this logs the success message properly
      if (evt instanceof HttpResponse) {
        //Keep going
      }
    },err => {
    console.log(err);
    //this logs the error but don't have useful info in it.
    });
}
}
Run Code Online (Sandbox Code Playgroud)
在成功的 http …
http web-deployment typescript angular-http-interceptors angular
我尝试了以下代码来实现表单的javaScript验证.当有人在Sign Up没有任何输入的情况下点击按钮时,div标签会Enter Your First Name在浏览器中显示.这正是我应该做的.但是,当有人在Sign Up没有输入的情况下命中两次时,不会调用该函数,而是发送给服务器.
我想知道在下面的代码中要做出哪些更改,以确保用户在将其发送到服务器之前被强制输入内容.任何帮助将不胜感激.提前致谢.
 <script language="javascript">
            var flag=0;
            function firstname()
            {
                firstname=join.firstname.value;
                if(firstname=="")
                {
                    document.getElementById("errorFname").innerHTML="Enter Your First Name";
                    flag=1;
                }   
              }
      function check(form)
            {
                flag=0;
                firstname();
                if(flag==1)
                    return false;
                else
                    return true;
            }
    </script>
       <form id= "join"  class="form-signUp" name="join" action="http://cs-sun2000.uscupstate.edu/~student1/cgi-bin/echo.cgi" method= "post" onSubmit="return check(this)">
        <div id="errorFname"></div><br><input name="firstname" type="text" placeholder="First Name" onBlur="firstname()" >
<button  name="submit" type="submit" >Sign Up</button>
        </form>
Run Code Online (Sandbox Code Playgroud)

我有以下代码来使用JavaScript. 有一个结帐链接,用于getcookie()检查存储的 cookie 的值。当 cookie 中没有任何内容时,请单击链接警报进行输入。如果在输入框中未输入任何值并点击“添加到购物车”,则验证完成并发出错误消息警报。
由于某种原因,cookie 没有从输入字段获取值。我尝试了很长一段时间,但无法调试代码。最后只显示一个空的警告框。我很欣赏任何调试。提前致谢。
<script type="text/javascript">
    var value;
    var productID;
    function setItem(abd) {
        value = abd.value;
        productID = abd.getAttribute("productID");
        var intRegex = /^\d+$/;
        var numberOfItems;
        if (!intRegex.test(value) || (value <= 0)) {
            alert('Please Enter valid numberofitem');
        } else {
            numberOfItems = value;
        }
    }
    function getCookie() {
        if (value == undefined) {
            alert("There is nothing in the shopping cart!");
        } else {
            var cookieArray = document.cookie.split(';');
            var printHolder = "";
            for (var …Run Code Online (Sandbox Code Playgroud) javascript ×3
html ×2
ionic ×2
.net ×1
angular ×1
angularjs ×1
c# ×1
command-line ×1
cookies ×1
cordova ×1
email ×1
gradle ×1
http ×1
jasmine ×1
java ×1
linux ×1
precision ×1
rounding ×1
setcookie ×1
shell ×1
typescript ×1
unit-testing ×1
unix ×1
validation ×1
windows ×1