This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// Typed variables raise type errors | |
var typed1 = 1; | |
// typed1 = '2'; | |
int typed2; | |
// typed2 = '2'; | |
// Dynamic types don't raise type errors | |
var a; | |
a = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h.select(&:matcher) | |
# => {:a=>"this"} | |
# Sorry what? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# irb / rails c / whatever | |
h = { a: "this", b: "that" } | |
h.select{ |k, v| v.match?("this") } | |
# => {:a=>"this"} | |
def matcher(string) | |
string.match?("this") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/rails/rails/issues/6769 | |
# https://github.com/rails/rails/issues/10621 | |
# https://stackoverflow.com/questions/19353507/eager-loading-the-first-record-of-an-association | |
# https://stackoverflow.com/questions/29142478/eager-load-only-first-associations-with-activerecord | |
# https://stackoverflow.com/questions/46415817/eager-loading-not-working-with-order-clause-in-rails | |
# https://stackoverflow.com/questions/52889750/eager-loading-with-scope-in-rails | |
# https://stackoverflow.com/questions/30056163/eager-loading-in-deep-level-nested-association | |
# https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Eager+loading+of+associations | |
# https://stackoverflow.com/questions/29804377/rails-4-eager-load-limit-subquery | |
# https://stackoverflow.com/questions/6477614/how-do-you-do-eager-loading-with-limits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jest.mock("MyOtherComponent", () => { | |
return require | |
.requireActual("TestUtils") | |
.mockOriginalFunctionality("MyOtherComponent"); | |
}); | |
describe("<Component />", () => { | |
it("works", () => { | |
// MyOtherComponent works as usual | |
}): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const mockOriginalFunctionality = name => { | |
const actualModule = require.requireActual(name); | |
return { | |
...Object.getOwnPropertyNames(actualModule) | |
.map(functionName => { | |
return { | |
[functionName]: jest.fn().mockImplementation(() => { | |
return actualModule[functionName](); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("<Component />", () => { | |
it("works", () => { | |
// ... | |
}): | |
describe("when something silly happens", () => { | |
beforeEach(() => { | |
jest.mock("MyOtherComponent", () => { | |
// ... | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://codeburst.io/javascript-null-vs-undefined-20f955215a2 | |
// With default parameters, `null` does not use default parameters | |
let logDefault = (str = 'default') => { | |
console.log(str); | |
} | |
logHi(); | |
// => hi | |
logHi(undefined); | |
// => hi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# db/seeds/test.rb | |
build_stubbed(:user) | |
def seed_user_pagination_data | |
FactoryBot.create_list(:user, 10) | |
end | |
# user_spec.rb | |
it "returns user" do | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
group :development, :test do | |
gem 'factory_bot_rails', require: false | |
end | |
# For testing: | |
# spec_helper.rb / rails_helper.rb | |
require 'factory_bot_rails' | |
# For other envs, e.g. development |