I am working on a website and it's running fine (online). I used angularjs for the javascript. I already minified all my angularjs code. But now, I put some new files called app-v2.js which is a javascript file. But, the new files I added seems not working. When I see the console of my browser it says like this Error: [$controller:ctrlreg] http://errors.angularjs.org/1.6.1/$controller/ctrlreg?p0=v2-ctrl. That errors mean that the controller v2-ctrl was not found/defined. But when i double check my files and codes it was there. Why is this happening? Here is my app-v2.js code:
(function(){
'use strict';
app.controller('v2-ctrl',['$scope','$http','$sce','$window','$timeout','$location','$route','$document', function($scope,$http,$sce,$window,$timeout,$location,$route,$document){
$scope.getAwards = function(){
$http.post('angular?ng=awards',{}).then(function(response){
$scope.awards = response.data;
for(var i = 0; i<response.data.length;i++){
response.data[i].award_title = response.data[i].award_title.replace(/&/g, '&');
}
$scope.awards = response.data;
});
};
})();
NOTE: The app was already defined on the another js file.
I hope someone can help me. I'm really stucked.
HEY: You can see actual code here
Click this
Related
Hi working on a project at the moment and currently getting it to call the api, great! however I'm looking at refactoring my test files as there will be quite a few so initially this is how I've done it.
var chakram = require('chakram');
expect = chakram.expect;
var baseFixture = require('../../test/fixtures/');
it("Should return the matching test file", function () {
var response = chakram.get("http://testurl");
return expect(response).to.have.json(baseFixture + 'testfile.json')
});
However with the code above I'm getting this error.
Error: Cannot find module '../../../../test/fixtures'
If I put the json file into the variable at declared at the top with a call to base fixture within the function the test will pass.
Where am I going wrong?
Thanks in advance.
In my Protractor framework, I am using a POM model, so a lot of code resides in different .js files, which are then called into , at necessary junctions, to have the e2e tests.
I have a CompleteProfile.js file (dummy name), where I have a condition,
if profile_flag ===100,
then do nothing
else
complete profile (includes a lot of forms)
For the else portion, I have the code in a differentfillCustomerForms.js file, whose code is something like this
var completeprofile = function(){
this.locator = element(by.css('some_css_locator'));
this.locator.click();
browser.sleep(2000);
}
module.exports={
profileComplete1 = completeprofile
}
I'm using this from fillCustomerForms.js in my CompleteProfile.js as
var Profile = require('./fillCustomerForms.js');
var c_profile = new Profile.profileComplete1();
var compl_profile = function(){
this.someFunction= function(){
profile_flag = "90"
if profile_flag ==="100"{
then do nothing;
}else{
c_profile.completeprofile();
}
}
}
module.exports={
finalExp = compl_profile
}
Inside my spec.js, I am calling the CompleteProfile.js as
var Profile = require('./CompleteProfile.js');
var co_profile = new Profile.finalExp();
describe("Modules",()=>{
it('Modules that load other things',()=>{
//do other things neccessary
});
});
describe("Module",()=>{
it("should do something,"()=>{
co_profile.someFunction();
});
});
The first describe block is the one that loads the browser and checks for the URL and other test cases. My issue is when if I add the second describe block, then the URL that is sent in first describe block is rendered empty i.e. Chrome loads without any URL, and errors out due to timeout error. I have checked the code and it seems fine. What did I do wrong here.
I'm guessing this might have to do with some basics of JS, that I might have overlooked, but right now I'm not able to figure this one out.
You have a syntax error in your second testcase (the it function). Every callback of each testcase in Mocha requires to be resolved or rejected. e.g:
it('should ...', done => {
/* assertion */
done(/* passing a new instance of Error will reject the testcase*/);
});`.
The called function doesn't not return anything in the provided code snippet, I don't really see what you're trying to test for.
im running a rails app which im running Unit tests on the Javascript side (Using Teaspoon/Jasmine).
the funny thing is, on the function I call I KNOW Mustache.render function is working (Im able to console.log it's return value (which is the Mustache.render function) and see that it is working. However when I call that function from my unit tests im getting a:
Failure/Error: ReferenceError: Can't find variable: Mustache.
For reference I don't actually call the Mustache render function directly im simply calling the function that uses it and grabbing it's return value to check again.
I've been able to successfully grab and use various other functions and use them just fine, this one is just giving me trouble. Can the Mustache.render object not exist outside it's own file or scope or something?
Edit: Example code:
_makeSomething: function viewMakeSomething(data) {
const template = templates.something;
return Mustache.render(document.querySelector(template).innerHTML, data);
}
and my test code is simply:
it('_makeSomething object', function() {
let obj = {id: 1234, content: "_makeSomething Assertion", author: "Test User"}
let $something = _makeSomething(obj);
});
(Right now im just capturing it before I assert anything or split it up/etc...., but it's just calling it at all)
Problem is that you teaspoon doesn't have access to your dev/production assets pipelene. You should specify what JS to load for your tests. This is necessary to prevent loading all files from manifest to test some feature. Because this is unit testing.
From example:
//= require mustache
describe("My great feature", function() {
it("will change the world", function() {
expect(true).toBe(true);
expect(Mustache).toBeDefined();
});
});
so I was trying to bring my code to readable form but stumbled upon a kinda annoying problem.
So I wanted to outsource a class into an file, "require" it and than write the callback function in the main file for the readability. But the function in the outsourced file is not able to access the callback function. Here is the simplified problem:
file_a.js
function test_a(){
return "this is A"
}
var test_b = require('./lib/file_b.js').test_b
console.log(test_b())
file_b.js
function test_b(){
return test_a()
}
exports.test_b = test_b
I hope someone could tell me how to manage this problem :)
EDIT: This code is for a firefox addon !
test_a function has to be globally defined:
test_a = function(){
return "this is A"
}
var test_b = require('./lib/file_b.js').test_b
console.log(test_b())
Also, you have to return something in your test_b function:
function test_b(){
return test_a()
}
exports.test_b = test_b
Then you will have such output:
this is A
You can load both js files independently in the same HTML file.
Then, whichever code that you have that is referencing other files loaded on the page should be in a window.onload call (or using jQuery $(document).ready), so that it only runs when the two files are available on the page.
I'm trying to do a pretty basic example using meteor js.
In my lib folder (shared by client and server) i have the following code
if (typeof hair === 'undefined') {
hair = {};
}
if (!hair.dao) {
hair.dao = {};
}
hair.dao.store = (function() {
return new Meteor.Collection('store');
})();
In folder server/libs i have this code
Meteor.startup(function() {
console.log(hair.dao.store.find().fetch());
});
(Which log one element)
In my client/libs folder i have this code
var cursorStores;
cursorStores = hair.dao.store.find();
console.log(cursorStores.fetch());
(Which logs no element)
It used to work, but now it stops.
Just to be clear i'm running on windows, and i removed and added again the autopublish package.
The data probably hasn't reached the client yet when you do that find. Try wrapping those 3 lines of client code in a Deps.autorun
I think find needs to take an argument. See http://docs.meteor.com/#find
If you are wanting the first element there are other ways of getting it. http://docs.meteor.com/
Try find({}) with empty curly braces