It's called knowing your audience and them knowing you. I've told my wife some rather sexist jokes and she laughs because she knows I don't actually agree with the premises. Mind you, I also tell "man jokes" as well. For example, Why do blond women have bruises around their belly buttons?
Because blond men are stupid too.
For me, anything is fair game when it comes to jokes and humour. Years ago I had a really good friend who happened to be Black. The two of us would crack stereotype jokes at each other all the time, sometimes even playing up the stereotypes ourselves. It was all good fun and was never intended to be mean or hateful.
We'd get some weird looks from time to time but we didn't care, it just made us laugh harder.