Skip to content

Instantly share code, notes, and snippets.

@vtanathip
vtanathip / Angular-config-e2e-testing.js
Created August 27, 2013 13:57
Sometime when you use yeoman you must add more config to Gruntfiles.js & karma-e2e.conf.js to complete it. the easiest to test e2e in angular is open server with grunt and add proxies to karma-e2e.conf.js then run it. By the way I found that sometimes when you use old version of angular-generator yo will fail when run test (it will start up but …
//add this config to karma-e2e.conf.js
// Uncomment the following lines if you are using grunt's server to run the tests
proxies = {
'/': 'http://localhost:9000/'
};
// URL root prevent conflicts with the site root
urlRoot = '_karma_';
@vtanathip
vtanathip / Angular-Directive-Mock.js
Created August 26, 2013 15:37
In Angular when you want to unit test directive with templateUrl you must compile html to js and put it in $templateCache for use it ( solution is very easy with this plugin https://github.com/ericclemmons/grunt-angular-templates )
ngtemplates: {
myApp: {
options: {
base: 'app/templates', // $templateCache ID will be relative to this folder
prepend: 'templates/', // path to your templates files ( this will add path to it )
module: {
name: 'myAppTemplate', // (Optional) Explicitly define module name
define: true // (Optional) Define new module (Default: false)
}
},
@vtanathip
vtanathip / Angular-Controller-Mock.js
Last active December 21, 2015 15:29
Example AngularJS Controller Unit Testing ( Mock all Services dependencies )
'use strict';
angular.module('angularApp')
.controller('MainCtrl', function ($scope, $rootScope, loadConfig) {
//services dependecies ( should be mock )
$scope.loadConfig = loadConfig.getConfig('main', $rootScope.lang);
//function change route
$scope.createRoute = function(link) {
@vtanathip
vtanathip / Angular-Services-Mock.js
Last active December 21, 2015 15:19
Example AngularJS Services Unit Testing ( Mock all $http dependencies )
angular.module('angularApp')
.factory('loadConfig', function($http) {
return {
getPageInfo : function(page) {
return $http.get('configurations/en/' + page + '.json').then(
function(response) {
return response.data;
});
}
@vtanathip
vtanathip / Remove-All-Yo-And-Start-Over.txt
Last active December 21, 2015 08:59
When develop project with yeoman a lot dependencies on it and people ( and I ) have a lot out of date modules installed globally so remove all of yo stuff and start over is one way to fix it.
npm remove -g yo generator-* yeoman-generator
npm install -g yo generator-angular
@vtanathip
vtanathip / A-Yeo-Profile-Management.js
Last active December 21, 2015 05:49
grunt configuration for profile management with grunt replace plugin ref: https://github.com/outaTiME/grunt-replace
replace: {
local:{
options:{
variables:{
'host':'http://localhost'
},
prefix: '@@'
},
files: [
{src: ['app/scripts/services/services.js'], dest: 'app/scripts/prod/services/services.js'}