Edit in JSFiddle

// Code under test
var MyApp = function () {
    var getFlag = function () {
        return false;
    };

    var useFlagForSomething = function () {
        if (this.getFlag() === true) {
            return "It was true";
        } else {
            return "It was false";
        }
    };

    return {
        getFlag: getFlag,
        useFlagForSomething: useFlagForSomething
    };
};

// Specs
describe("Testing spies", function () {

    it("Should replace the return value of function being spied on", function () {
        // Arrange
        var myApp = new MyApp();
        spyOn(myApp, "getFlag").and.returnValue(true);

        // Act
        var result = myApp.useFlagForSomething();

        // Assert
        expect(result).toEqual("It was true");
    });

});