简体   繁体   English

如何在Jasmine中找到脚本SRC

[英]How Do I Find the Script SRC in Jasmine

I am REALLY new to Jasmine and am trying to write a unit test that checks if a URL is constructed properly from variables defined by the environment. 我是Jasmine的新手,正尝试编写一个单元测试,以检查是否根据环境定义的变量正确构建了URL。

describe('URL is built properly', function() {
        var newHead = '<!doctype html>' +
            '<html class="no-js" lang="">' +
            '    <head>' +
            '    </head>' +
            '<body>' +
            '</body>' +
            '</html>';

        beforeEach(function() {
            ScratchPad.clear();
            ScratchPad.add(newHead);
            debugger;
            spyOn(newSetup.prototype, 'createNewScript');
        });
        afterAll(function() {
            ScratchPad.clear();
        });

        it('should build Staging', function() {
            window.my.env = 'staging';
            window.my = {
                newScript: {
                    enabled: true,
                    location: 'google-com'
                }
            };

            var options = {
                windowWidth: 640
            };

            this.newScript = new newScriptSetup(options);
            var newHTML = ScratchPad.find('script')[0].src;
            debugger;
            expect(newHTML.src).toEqual('http://my.site.com/google-com/myScript.min.js');
        });
    });

The problem I seem to be having is that; 我似乎遇到的问题是;

expect(newHTML.src).toEqual('http://my.site.com/google-com/myScript.min.js');

this bit of the script isn't getting populated, I've tried debugging it and the var newHead is being created, it's just not being seen by the rest of the unit test... I think. 这部分脚本没有被填充,我已经尝试调试它,并且正在创建var newHead,其余的单元测试只是看不到它...我想。 Could someone help me out, I've been looking at it all day :( 有人可以帮我吗,我整天都在看着它:(

var newHTML = ScratchPad.find('script')[0].src;
debugger;
expect(newHTML.src)..

You are already getting the src in newHTML. 您已经在newHTML中获得了src You are trying to check .src.src with the url you provide. 您正在尝试使用提供的URL检查.src.src。 Try this: 尝试这个:

var newHTML = ScratchPad.find('script')[0].src;
expect(newHTML).toBe(..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM